Welcome Guest, Not a member yet? Register   Sign In
phptal & ci integration
#1

[eluser]Unknown[/eluser]
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,
Djang
#2

[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

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

// Do this:
$this->load->library('phptal');
$this->phptal->some_variable = $some_variable;
$this->phptal->setTemplate('path_to_template');
echo $this->phptal->execute();

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

[eluser]Unknown[/eluser]
Whoa, Rick, that was fast. Thanks a lot!

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

[eluser]esra[/eluser]
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.

<url>http://ci-ext.googlecode.com/svn/</url>

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.
#5

[eluser]Methyle[/eluser]
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:
Code:
$this->load->library('phptal');
$this->phptal->set('user', $this->user_model->get_user(1));
$this->phptal->setTemplate('user/index.html');
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?
#6

[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:
Code:
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.
#7

[eluser]Methyle[/eluser]
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):
Code:
<p tal:content="user/fistname"></p>
And i get this error:
[pre]
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
[/pre]
#8

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

[eluser]Methyle[/eluser]
Oh, I'm so sorry, I missed letter "r" Smile
#10

[eluser]meglio[/eluser]
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.




Theme © iAndrew 2016 - Forum software by © MyBB