ホームページ バックエンド開発 PHPチュートリアル フレームワークを推奨する投稿をいくつか読んだところですが、かなりの数の codeigniter が推奨されていますが、私の個人的な意見は参考程度に留めてください。

フレームワークを推奨する投稿をいくつか読んだところですが、かなりの数の codeigniter が推奨されていますが、私の個人的な意見は参考程度に留めてください。

Jun 23, 2016 pm 01:32 PM

まず、私は codeigniter を最初にフレームワークを学び始めたときに使用しましたが、その後、会社で thinkphp を使用し、その後 2 つを使用し始めました。まず、これら 2 つのフレームワーク フォルダーの容量は比較的大きく、軽量とは言えません。
今日は codeigniter フレームワークについてだけ話します
公式 Web サイトのコントローラーがテンプレートを呼び出す例を見てみましょう

<?phpclass Blog extends CI_Controller { function index() {  $data['title'] = "My Real Title";  $data['heading'] = "My Real Heading";    $this->load->view('blogview', $data); }}?> 
ログイン後にコピー

<html><head><title><?php echo $title;?></title></head><body> <h1><?php echo $heading;?></h1></body></html>
ログイン後にコピー


このモデルは非常に悪いと感じます これは伝説的なコントローラー テンプレートの分離ですか?このモデルは、それを使い始めたばかりの PHPer を騙すだけです。smarty などと言って私を反論するのではなく、そのモデル自体の特徴について話しましょう。どのフレームワークも Smarty と組み合わせて使用​​できます。

上記のコードはPHPの関数で実装できます。extract関数の使い方を確認してください。

codeigniter を使用する多くの PHPer は、おそらく、いわゆる美しい書き方を目的としてこれを使用します。 -> ->
本質的には、テンプレート (ビュー) にはあまり影響しません。まずすべての変数が計算され、名前が変更され、必要に応じて必要な場所に新しい名前が入力されます。

そこで海外のサイトを徘徊していたら、codeigniter モデルによく似たテンプレートを発見しました。テンプレート名は不明です。テンプレートと呼んでください。これを見て、codeigniter の原理を全体的に理解することができます

そのコア テンプレート コードを書きます
<?php//template.php/** * Copyright (c) 2003 Brian E. Lozier (brian@massassi.net) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to * deal in the Software without restriction, including without limitation the * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or * sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS * IN THE SOFTWARE. */class Template {	var $vars; /// Holds all the template variables	var $path; /// Path to the templates	/**	 * Constructor	 *	 * @param string $path the path to the templates	 *	 * @return void	 */	function Template($path = null) {		$this->path = $path;	}	/**	 * Set the path to the template files.	 *	 * @param string $path path to template files	 *	 * @return void	 */	function set_path($path) {		$this->path = $path;	}	/**	 * Set a template variable.	 *	 * @param string $name name of the variable to set	 * @param mixed $value the value of the variable	 *	 * @return void	 */	function set($name, $value) {		$this->vars[$name] = $value;	}	/**	 * Open, parse, and return the template file.	 *	 * @param string string the template file name	 *	 * @return string	 */	function fetch($file) {		extract($this->vars);          // Extract the vars to local namespace		ob_start();                    // Start output buffering		include($this->path . $file);  // Include the file		$contents = ob_get_contents(); // Get the contents of the buffer		ob_end_clean();                // End buffering and discard		return $contents;              // Return the contents	}}/** * An extension to Template that provides automatic caching of * template contents. */class CachedTemplate extends Template {	var $cache_id;	var $expire;	var $cached;	/**	 * Constructor.	 *	 * @param string $path path to template files	 * @param string $cache_id unique cache identifier	 * @param int $expire number of seconds the cache will live	 *	 * @return void	 */	function CachedTemplate($path, $cache_id = null, $expire = 900) {		$this->Template($path);		$this->cache_id = $cache_id ? 'cache/' . md5($cache_id) : $cache_id;		$this->expire   = $expire;	}	/**	 * Test to see whether the currently loaded cache_id has a valid	 * corrosponding cache file.	 *	 * @return bool	 */	function is_cached() {		if($this->cached) return true;		// Passed a cache_id?		if(!$this->cache_id) return false;		// Cache file exists?		if(!file_exists($this->cache_id)) return false;		// Can get the time of the file?		if(!($mtime = filemtime($this->cache_id))) return false;		// Cache expired?		if(($mtime + $this->expire) < time()) {			@unlink($this->cache_id);			return false;		}		else {			/**			 * Cache the results of this is_cached() call.  Why?  So			 * we don't have to double the overhead for each template.			 * If we didn't cache, it would be hitting the file system			 * twice as much (file_exists() & filemtime() [twice each]).			 */			$this->cached = true;			return true;		}	}	/**	 * This function returns a cached copy of a template (if it exists),	 * otherwise, it parses it as normal and caches the content.	 *	 * @param $file string the template file	 *	 * @return string	 */	function fetch_cache($file) {		if($this->is_cached()) {			$fp = @fopen($this->cache_id, 'r');			$contents = fread($fp, filesize($this->cache_id));			fclose($fp);			return $contents;		}		else {			$contents = $this->fetch($file);			// Write the cache			if($fp = @fopen($this->cache_id, 'w')) {				fwrite($fp, $contents);				fclose($fp);			}			else {				die('Unable to write cache.');			}			return $contents;		}	}}?>
ログイン後にコピー

コア テンプレート クラスでは、extract($this->vars); 関数も使用されます。配列を分割します。

彼の「コントローラー」の使い方を見てみましょう
<?php//user_list.phprequire_once('template.php');/** * This variable holds the file system path to all our template files. */$path = './templates/';/** * Create a template object for the outer template and set its variables. */$tpl = & new Template($path);$tpl->set('title', 'User List');/** * Create a template object for the inner template and set its variables.  The * fetch_user_list() function simply returns an array of users. */$body = & new Template($path);$body->set('user_list', fetch_user_list());/** * Set the fetched template of the inner template to the 'body' variable in * the outer template. */$tpl->set('body', $body->fetch('user_list.tpl.php')); //这个是直接调用模板/** * Echo the results. */echo $tpl->fetch('index.tpl.php');/** * Just a function to simulate the retrieval of a user list. */function fetch_user_list() {	return array(		array('id' => 1,		      'name' => 'bob',			  'email' => 'bob@mozilla.org',			  'banned' => false),		array('id' => 2,		      'name' => 'judy',			  'email' => 'judy@php.net',			  'banned' => false),		array('id' => 3,		      'name' => 'joe',			  'email' => 'joe@opera.com',			  'banned' => false),		array('id' => 4,			  'name' => 'billy',			  'email' => 'billy@wakeside.com',			  'banned' => true),		array('id' => 5,		      'name' => 'eileen',			  'email' => 'eileen@slashdot.org',			  'banned' => false));}?>
ログイン後にコピー


セットは割り当てです。次に、その「ビュー」がどのように出力されるかを見てください。基本的に codeigniter に似ています
//index.tpl.php<html>	<head>		<title><?=$title;?></title>	</head>	<body>		<h2><?=$title;?></h2><?=$body;?>	</body></html>
ログイン後にコピー

//user_list.tpl.php<table>	<tr>		<th>Id</th>		<th>Name</th>		<th>Email</th>		<th>Banned</th>	</tr><? foreach($user_list as $user): ?>	<tr>		<td align="center"><?=$user['id'];?></td>		<td><?=$user['name'];?></td>		<td><a href="mailto:<?=$user['email'];?>"><?=$user['email'];?></a></td>		<td align="center"><?=($user['banned'] ? 'X' : ' ');?></td>	</tr><? endforeach; ?></table>
ログイン後にコピー


詳細なダウンロード アドレス: http://download.csdn.net/detail/xjl756425616/3984218



ディスカッションに返信(解決策)

Copyright (c) 2003 ....
10 年前! ! !

今日が4月1日だからって?


LZ はいくつかのフレームワークを推奨しています。 ~

php アンプ

どう思います

Copyright (c) 2003 ....
10 年前! ! !

今日が4月1日だからって?


テクノロジーと日付の関係は何ですか? codeigniter メソッドとよく似ていると思います~



LZ はいくつかのフレームワークを推奨しています! ~
おすすめはありません~ 私はこの 2 つしか使用したことがありませんが、包括的な比較はありません。

//template.php

/**

* Copyright (c) 2003 Brian E. Lozier (brian@massassi.net)

返信

codeigniter はテンプレート エンジンではありません
フレームワークはもちろん、独自のテンプレートエンジンも持っています

10年前のものは古すぎる

あなたも新しくて違うものになりたいと思いませんか?

4.1 エイプリル フール




php amp
どう思いますか?

まずはダウンロードして見てみましょう

あなたのテンプレートと CI の違いは何ですか?
結局のところ、テンプレートはob+extractではないのですか?

php amp
どう思いますか?

見ましたが、特にコメントすることはありません。そのテンプレート エンジンに似ています


CI をお勧めします。使いやすく、テンプレートはすべて同じです。 ,


実際、正しいフレームワークも間違ったフレームワークもありません。たとえば、私の会社のプロジェクトは現在緊急であり、新人は皆、使用経験がある人に非常に適しています。このフレームワークは基本的に 1 ~ 2 日で開発を開始できます

ただし、限界も明らかです…

MVC は分業が細かく、コードがシンプルでわかりやすいと個人的には思います。


CI は問題なく使用しています。

php amp

どう思いますか?

見たけど、コメントすることは何もない、あのテンプレートエンジンに似てる

フレームワークの 99% がこれを使っているので、余分なものは何も問題ないたとえば、yii2:
public function renderPhpFile($_file_, $_params_ = [])    {        ob_start();        ob_implicit_flush(false);        extract($_params_, EXTR_OVERWRITE);        require($_file_);        return ob_get_clean();    }
ログイン後にコピー


dedecms など、eval() を使用するものもあります。 。 。 。 。 。 。 。 。 。 。 。 。

このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

AI Hentai Generator

AI Hentai Generator

AIヘンタイを無料で生成します。

ホットツール

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

SublimeText3 中国語版

SublimeText3 中国語版

中国語版、とても使いやすい

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強力な PHP 統合開発環境

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)

Laravelでフラッシュセッションデータを使用します Laravelでフラッシュセッションデータを使用します Mar 12, 2025 pm 05:08 PM

Laravelは、直感的なフラッシュメソッドを使用して、一時的なセッションデータの処理を簡素化します。これは、アプリケーション内に簡単なメッセージ、アラート、または通知を表示するのに最適です。 データは、デフォルトで次の要求のためにのみ持続します。 $リクエスト -

PHPロギング:PHPログ分析のベストプラクティス PHPロギング:PHPログ分析のベストプラクティス Mar 10, 2025 pm 02:32 PM

PHPロギングは、Webアプリケーションの監視とデバッグ、および重要なイベント、エラー、ランタイムの動作をキャプチャするために不可欠です。システムのパフォーマンスに関する貴重な洞察を提供し、問題の特定に役立ち、より速いトラブルシューティングをサポートします

PHPのカール:REST APIでPHPカール拡張機能を使用する方法 PHPのカール:REST APIでPHPカール拡張機能を使用する方法 Mar 14, 2025 am 11:42 AM

PHPクライアントURL(CURL)拡張機能は、開発者にとって強力なツールであり、リモートサーバーやREST APIとのシームレスな対話を可能にします。尊敬されるマルチプロトコルファイル転送ライブラリであるLibcurlを活用することにより、PHP Curlは効率的なexecuを促進します

Laravelテストでの簡略化されたHTTP応答のモッキング Laravelテストでの簡略化されたHTTP応答のモッキング Mar 12, 2025 pm 05:09 PM

Laravelは簡潔なHTTP応答シミュレーション構文を提供し、HTTP相互作用テストを簡素化します。このアプローチは、テストシミュレーションをより直感的にしながら、コード冗長性を大幅に削減します。 基本的な実装は、さまざまな応答タイプのショートカットを提供します。 Illuminate \ support \ facades \ httpを使用します。 http :: fake([[ 'google.com' => 'hello world'、 'github.com' => ['foo' => 'bar']、 'forge.laravel.com' =>

Codecanyonで12の最高のPHPチャットスクリプト Codecanyonで12の最高のPHPチャットスクリプト Mar 13, 2025 pm 12:08 PM

顧客の最も差し迫った問題にリアルタイムでインスタントソリューションを提供したいですか? ライブチャットを使用すると、顧客とのリアルタイムな会話を行い、すぐに問題を解決できます。それはあなたがあなたのカスタムにより速いサービスを提供することを可能にします

PHPにおける後期静的結合の概念を説明します。 PHPにおける後期静的結合の概念を説明します。 Mar 21, 2025 pm 01:33 PM

記事では、PHP 5.3で導入されたPHPの後期静的結合(LSB)について説明し、より柔軟な継承を求める静的メソッドコールのランタイム解像度を可能にします。 LSBの実用的なアプリケーションと潜在的なパフォーマ

フレームワークのカスタマイズ/拡張:カスタム機能を追加する方法。 フレームワークのカスタマイズ/拡張:カスタム機能を追加する方法。 Mar 28, 2025 pm 05:12 PM

この記事では、フレームワークにカスタム機能を追加し、アーキテクチャの理解、拡張ポイントの識別、統合とデバッグのベストプラクティスに焦点を当てています。

See all articles