开发者

Difference between PHP and PHP in CODEIGNITER coding formats

开发者 https://www.devze.com 2023-03-20 19:33 出处:网络
Is there any difference writing the code in normal php and php in codeigniter. If so what are the difference between normal php coding and php in codeigni开发者_开发技巧ter.

Is there any difference writing the code in normal php and php in codeigniter. If so what are the difference between normal php coding and php in codeigni开发者_开发技巧ter. For eg:

Normal PHP code

 $pdf = new PDFMerger;
 $pdf->addPDF($1, 'all')
     ->addPDF($2, 'all')
     ->merge('file',$1);

How will this be written in codeigniter. Thanks for ur time.


It would be written exactly the same.

CodeIgniter is not a new language, it's simply a framework. Just because you're writing MVC-style code or using external classes doesn't mean that your coding style should change at all.

There are some styles that they would like you to follow, but they certainly shouldn't change your code drastically as they're pretty much common sense. Read about them here.

Also, it's best practice to always include parentheses when initialising a class, this way if it doesn't look different than a class with parameters and it's always nicer to be consistent :)

$pdf = new PDFMerger();
$other = new OtherClass($pdf);

Finally, the only thing you should(?) change, style-wise, is the last line, add a space inbetween the parameters. Again, for consistency and readability.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号