Notes On <Codeigniter for Rapid PHP Application Development> - 01

Principles of Design:


cover


Loose Coupling





File Structure:





URL Pattern in Favor of MVC




If no function is specified, the route defaults to the /index function of whatever controller is selected, so make sure you include an index function, if only to prevent '404' pages. Please note that the index function is not the same as the constructor function. 
You can alter this default if you like, by including in the controller(s) you want to alter, a function called _remap($function), where $functionis the function you want to intercept and redirect. _remap always gets called first, whatever the URL says. 


You must always include index.php in your URL, CodeIgniter is different from Zend Framework, it doesn't have a BootStrap.



Chapter 3:


The sample code in this chapter is definitely wrong!


First of all, in the view file, application/views/testview/php, the html opening tag is repeated, and DOCTYP declaration should be outside.


It should be:

<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'http:\/\/www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
<html xmlns='http:\/\/www.w3.org/1999/xhtml'>
	<head>
	
		<title>Web test Site</title>
		<base href= <?php echo "$base"; ?> >
		<link rel="stylesheet" type="text/css" href="<?php echo "$base/$css";?>">
	</head>
	<body>
		<h1><?php echo $mytitle; ?> </h1>
		<p class='test'> <?php echo $mytext; ?> </p>
	</body>
</html>


And the controller file: application/controllers/start.php, the Start class is extending Controller, and call Controller::Controller() method, this is not obeying the current official document. Maybe it is due to version change, anyway, it should be changed, otherwise you will get error:


Fatal error: Class 'Controller' not found in C:\EasyPHP-5.3.6.1\www\CfRPAD\application\controllers\start.php on line 2


The correct version is:

<?php
class Start extends CI_Controller {
	var $base;
	var $css;
	function Start()
	{
		parent::__construct();
		$this->base = $this->config->item('base_url');
		$this->css = $this->config->item('css');
	}
	function hello($name)
	{
		$data['css'] = $this->css;
		$data['base'] = $this->base;
		$data['mytitle'] = 'Welcome to this site';
		$data['mytext'] = "Hello, $name, now we're getting dynamic!";
		$this->load->view('testview', $data);
	}
}


Note that, to let this sample work fine, you at least need to update $config['base_url'] in config.php.


Chapter 4:


For some reasons, when I create the database, I switch engine from MyISAM to InnoDB, and switch DEFAULT CHARSET from latin1 to utf8.


I found a table named ci_session, interesting~~


Chapter 5:

In the sample code of the first approach for nesting view, there is mistake of header_view.php, the mistype of quotation marks, it should be:

<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<title><?php echo $mywebtitle ?></title>
<base href=<?php echo "$base"; ?>>
<?php echo $myrobots ?>
<link rel="stylesheet" type="text/css" 	href='<?php echo "$base/$css"; ?>'>


This method is just call load->view('the inner view') within the outer view.


However, as to the second way, the author didn't state it clearly, about how to output the inner view as a registered variable inside outer view, if we change basic_view from:

<html>
<head>
<?php $this->load->view('header_view'); ?>
</head>
<body>
	<h1 class='test'><?php echo $mytitle; ?></h1>
	<p class='test'><?php echo $mytext; ?></p>
</body>
</html>


to:

<html>
<head>
<?php echo $header; ?>
</head>
<body>
	<h1 class='test'><?php echo $mytitle; ?></h1>
	<p class='test'><?php echo $mytext; ?></p>
</body>
</html>


Then, we got error, all the place inside the inner view that outputting a variable will be put a block of HTML markup:

<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message:  Undefined variable: base</p>
<p>Filename: views/header_view.php</p>
<p>Line Number: 6</p>

</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message:  Undefined variable: css</p>
<p>Filename: views/header_view.php</p>
<p>Line Number: 6</p>

</div>


It will be rendered as warning message..... This method failed.



Chapter 6: Simplifying Session and Security


Session 類別



Chapter 7: CodeIgniter and Objects



Super-Object


Chapter 8: Using CI to Test Code


For now, just remember the usage of log_message() is enough.

Unit Test Class(skip)

CI's Benchmarking Class(skip)

CI's Profiler Class(skip)

Testing with Mock Databases(skip)


Chapter 9: Using CI to Communicate


Using the FTP Class to Test Remote Files(skip)


Machines Talking to Machines Again—XML-RPC(skip)


Talking to Humans for a Change: the Email Class

$this->email->initialize($config);

$this->email->from('david@mysite.com');
$this->email->to('someone@myownsite.com'); 
$this->email->bcc('fred@somewhere.com'); 
$this->email->subject('Test message');
$this->email->message('Hello world'); 

$path = $this->config->item('server_root');
$file = $path.'/my_subdirectory/myfile.htm';
$this->email->attach($file);

$this->email->send();



Chapter 10: How CI Helps to Provide Dynamic Information

The Date Helper: Converting and Localizing Dates(skip)

Working with Text: the Text Helper and Inflector Helper(skip)

Going International: the Language Class


system/language/English/

system/language/Chinese/

system/language/Cantonese/


<?php
$lang['welcome_title'] = 'Welcome to this site';
$lang['welcome_text1'] = 'Hello ';
$lang['welcome_text2'] = ' now we're getting dynamic';
?>



$this->lang->load('welcome', 'german');// english is default
$data['mytitle']= $this->lang->line('welcome_title');
...
$this->load->view('testview', $data);




评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值