10000 coverting rain variable coming from db · Issue #156 · feulf/raintpl3 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

coverting rain variable coming from db #156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
AhmedMElmetwally opened this issue Jun 17, 2014 · 11 comments
Open

coverting rain variable coming from db #156

AhmedMElmetwally opened this issue Jun 17, 2014 · 11 comments

Comments

@AhmedMElmetwally
Copy link

hey everybody

how can i convert variable coming from database ?

@feulf
Copy link
Owner
feulf commented Jun 22, 2014

Use PDO to get the query in array format and assign that variable into the
template.

You can also use a DB wrapper such as RainFramework DB:
http://www.rainframework.com/User-Guide/Library/DB/get_row/

On Tue, Jun 17, 2014 at 7:28 PM, Luffy-php notifications@github.com wrote:

hey everybody

how can i convert variable coming from database ?


Reply to this email directly or view it on GitHub
#156.

@AhmedMElmetwally
Copy link
Author

thx for ur reply ,
but i want to convert for example
i have two columns in my mysql
id , content
content = {$site_name}
i want to get the content and assign it , then assign the value of {$site_name}

@feulf
Copy link
Owner
feulf commented Jun 22, 2014

All you've to do is to get the value of $site_name from the database:

// I'm using RainFramework DB but you can use PDO or any other MySQL library
$site_name = Db::getField("site_name", "SELECT site_name FROM your_table
WHERE id=':id'", array('id'=>'site_name'));

// then you assign $site_name to your template:
$t = new Rain\Tpl();
$t->assing('site_name', $site_name);
$t->draw('your_template');

and into the template you simply use {$site_name}.

<title>{$site_name}</title>

On Sun, Jun 22, 2014 at 12:07 PM, Luffy-php notifications@github.com
wrote:

thx for ur reply ,
but i want to convert for example
i have two columns in my mysql
id , content
content = {$site_name}
i want to get the content and assign it , then assign the value of
{$site_name}


Reply to this email directly or view it on GitHub
#156 (comment).

@AhmedMElmetwally
Copy link
Author

screenhunter_01 jun 23 15 12
thanks rain
i will explain ,
i dont want to assign value directly because i dont control the variable
as i said the variable is stored in mysql
i first fetch the column content , then assign the content
in the content there is variable i want to complie variable coming from database , compile variable then compile variable coming from the compiled variable
please take a shot http://s10.postimg.org/igp3ed9h5/Screen_Hunter_01_Jun_23_15_12.jpg

@feulf
Copy link
Owner
feulf commented Jun 23, 2014

use drawString then, here's an example:
https://github.com/rainphp/raintpl3/blob/master/example-draw-string.php

On Mon, Jun 23, 2014 at 8:15 AM, Luffy-php notifications@github.com wrote:

thanks rain
i will explain ,
i dont want to assign value directly because i dont control the variable
as i said the variable is stored in mysql
i first fetch the column content , then assign the content
in the content there is variable i want to complie variable coming from
database , compile variable then compile variable coming from the compiled
variable
please take a shot
http://s10.postimg.org/igp3ed9h5/Screen_Hunter_01_Jun_23_15_12.jpg


Reply to this email directly or view it on GitHub
#156 (comment).

@AhmedMElmetwally
Copy link
Author

Thanks rain 👍
i will try it then comment

@AhmedMElmetwally
Copy link
Author

I could not use drawString :(
i am using SQL to save loops or if statement not only variable
such as
kit-pc02 jul 06 06 32 16 pm
could you help plz

@feulf
Copy link
Owner
feulf commented Jul 6, 2014

It should work, drawString works like draw with the only difference that the templates is coming from a string. Please explain more in details what you want to do and I'll help you to find a better solution.

@AhmedMElmetwally
Copy link
Author

Thanks a lot friend
i want to do blocks system in my script
the whole block will be saved in SQL table
most of blocks will have template variables, if statements or loops
i will extract all blocks from database and assigning it to array width PDO
in my template i want to make it work
$array = array(
"name" => "register_block",
"block_content" => "{if='$_SESSION[user] == allow'}do something{/if}"
);
$tpl->assign( $array );
$tpl->draw( "blocks" );
i want {if='$_SESSION[user] == allow'}do something{/if} to be compiled in my template

@feulf
Copy link
Owner
feulf commented Jul 6, 2014

You're passing variables to the template, those variables are rendered as
strings why they're not executed, the only way to execute that code is to
parse it with drawString first:

$block_content = $this->drawString("your string here");

and then:
$array = array("name" => "register_block", "block_content" =>
$register_block);

My recommendation is to move from your database the business logic and the
presentation logic, into the controller and specific templates, keep your
code, template and database as less entangled as possible and as simple as
possible!

On Sun, Jul 6, 2014 at 4:29 PM, Luffy-php notifications@github.com wrote:

Thanks a lot friend
i want to do blocks system in my script
the whole block will be saved in SQL table
most of blocks will have template variables, if statements or loops
i will extract all blocks from database and assigning it to array width PDO
in my template i want to make it work
$array = array(
"name" => "register_block",
"block_content" => "{if='$_SESSION[user] == allow'}do something{/if}"
);
$tpl->assign( $array );
$tpl->draw( "blocks" );
i want {if='$_SESSION[user] == allow'}do something{/if} to be compiled in
my template


Reply to this email directly or view it on GitHub
#156 (comment).

7A32

@AhmedMElmetwally
Copy link
Author

Thank you so much :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0