• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
phptal & ci integration

Can someone please give me a hint where/how to integrate phptal and ci. I am not sure I want to mess with a templating system *and* ci, but at least wanted to give it a whiz.

Thanks in advance,

[eluser]Rick Jolly[/eluser]
Using phptal is straightforward.

To integrate phptal:
- Simply treat it like any other CI library. Put PHPTAL.php (but change the name to Phptal.php for CI case conventions) and the PHPTAL folder in CI libraries folder.

To use phptal:
- load it like any other CI library
- replace CI views with phptal

// Instead of this:
$data['some_variable'] = $some_variable;
$this->load->view('template', $data);

// Do this:
$this->phptal->some_variable = $some_variable;
echo $this->phptal->execute();

Nice to know that someone else is interested in phptal. Let me know if you require anything else.

Whoa, Rick, that was fast. Thanks a lot!

That looks easy enough. I'll roll up my sleeves immediately ...

There should be a contribution on the wiki called something like ci_ext. If not, do a search on the web. Among other things, it demonstrates how to integrate phpTAL with CI.

EDIT: the svn site on Google is here.


For your reference, you might try doing a web search first before posting. There is a lot of nice CI-related code on blogs or posted as tutorials throughout the web. Much of it is not mentioned in the wiki or in the forums. You might find what your looking for faster.

Rick, I did all you wrote, but got error message:

Fatal error: require_once() [function.require]: Failed opening required 'PHPTAL/Source.php' (include_path='.;/usr/local/php5/PEAR;z:\home\www/system/application/pear/') in z:\home\www\system\application\libraries\PHPTAL\FileSource.php on line 3

This is my code:
$this->phptal->set('user', $this->user_model->get_user(1));
echo $this->phptal->execute();

What should I do with this problem?

Another question: is it possible to use arrays in PHPTAL templates without tal:repeat? For example my model's function get_user() returns $query->row(), and now in my view I'm using code like this &lt;?=user->firstname;?&gt;. How to modify this code for PHPTAL?

[eluser]Rick Jolly[/eluser]
My apologies, you also have to add PHPTAL to the include path (the same applies for other packaged libraries like PEAR and Zend Framework components). You can put something like this in your config.php file since that is always loaded by CI:
ini_set('include_path',ini_get('include_path'). PATH_SEPARATOR . APPPATH . 'libraries/');
The example above assumes that your PHPTAL folder is in your application libraries directory. I see that you currently have it in your system library directory - I'd move it for easier CI upgrading.

The answer to the second question is yes. The best place to discover how is in the phptal docs. Let me know if you would like to know more.

It's very strange - I put PHPTAL to application/libraries as well you wrote. Ok, I added include path for PHPTAL. But now I have new problem with template. My template is very simple (controller above):
<p tal:content="user/fistname"></p>
And i get this error:
Fatal error: Uncaught exception 'Exception' with message 'Unable to find array key &quot;fistname&quot; in path &quot;fistname&quot;' in z:\home\www\system\application\libraries\PHPTAL\Context.php:299
Stack trace:
#0 z:\home\www\system\application\cache\tpl_1_1_85248dbbd73b5d022e3f62a105f827d67.php(6): phptal_path(Array, 'fistname')
#1 z:\home\www\system\application\libraries\PHPTAL.php(284): tpl_1_1_85248dbbd73b5d022e3f62a105f827d67(Object(PHPTAL), Object(PHPTAL_Context))
#2 z:\home\www\system\application\controllers\user.php(26): PHPTAL-&gt;execute()
#3 [internal function]: User-&gt;index()
#4 z:\home\www\system\codeigniter\CodeIgniter.php(216): call_user_func_array(Array, Array)
#5 z:\home\www\index.php(132): require_once('z:\home\yolk\ww...')
#6 {main}
thrown in z:\home\www\system\application\libraries\PHPTAL\Context.php on line 299

[eluser]Rick Jolly[/eluser]
Spelling mistake: fistname?

Oh, I'm so sorry, I missed letter "r" Smile

I also like PHPTAL and I use it everywhere so I found this combination very useful: CodeIgniter + PHPTAL.

Thank you for this quick review on how to combine them together by using PHPTAL as library.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.