Welcome Guest, Not a member yet? Register   Sign In
use user define function in CI
#1

[eluser]ranjitbd[/eluser]
//i have a common.php file where more than 100 customise function is exist for my usages.one of them shown below
<?php
function toPascalCase($str)
{
return strtoupper($str[0]). strtolower(substr($str,1,(strlen($str)-1)));
}
?>


//this code exist in my header section and i used the customise function toPascalCase($str).so i have to include the
//at first i include common.php file in my index page.

<?php include(BASEPATH.'common.php');?>

<?php
if($this->session->userdata('logged_in')==TRUE)
{
echo toPascalCase($this->session->userdata('name'));
}

?>
//my 1st question is: is it good practice to include a file such a way and use the user_define function like that way
// 2nd question is: if it is not a good practice then how can i load the common.php file via autoload or config file
// and use those customise function.
// 3rd question is: the above code is exist in header that is inside views folder.if i need to use customise function
from common.php in a method that is inside controller....then what to do?
#2

[eluser]pistolPete[/eluser]
Please wrap [ code ] tags around your code samples!

I'd rather create a helper and put the functions in there: http://ellislab.com/codeigniter/user-gui...lpers.html
You can then autoload your helper:
http://ellislab.com/codeigniter/user-gui...oader.html

After the helper is loaded, you can access its functions from both the controller and the view.




Theme © iAndrew 2016 - Forum software by © MyBB