CI helper variable is not accessing in view file - php

I load a helper file and it is included successfully
The constants variable in helper file such as
Define("FIELD_VALID", "valid");
If i echo FIELD_VALID in view file...it works
But there is assigned variable in helper file such as
$strSite="http://www.mysite.com/";
If i echo $strSite in view file, it prints nothing
Hoping for the answer
Thanks.

What you are trying to do would be much better accomplished with a custom config file. Look at this: http://codeigniter.com/user_guide/libraries/config.html

Related

How do I read from a yml file in a controller in symfony2?

I have a random name.yml file inside lets say my src/AppBundle/Controller folder. The content inside the YML file is simple:
name: utkarsh
I need to access this from my controller, and have tried to fetch them with
$name = $this->getName('name');
from within my controller file. When I try this, I get this error message:
Attempted to call an undefined method named "getName" of class "AppBundle\Controller\DefaultController".
What is the correct way to do this?
If it's just going to be a general file, and wouldn't better be part of the framework's configuration (for example, in the parameters.yml file), you can parse/read the file using the Yaml component, which is already used by the Symfony framework.
use Symfony\Component\Yaml\Yaml;
$values = Yaml::parse(file_get_contents('/path/to/name.yml'));
echo $values['name'];
If the file you are loading is in the same directory as the code that is running it, you can use the PHP Automagic constants - __DIR__, file_get_contents(__DIR__ . '/name.yml'), or use it as a relative base to work from.
Don't just put your YML file in the Controllers folder. Instead, move your YML file into your bundles' config directory. See below,
AppBundle\Resource\config\abc.yml
Then, import this file in your services.yml file. See below,
imports:
- { resource: abc.yml }
And, make sure you abc.yml file will have a structure like this,
parameters:
name: utkarsh
Finally, you can access this parameter inside the Controller by calling like this,
$this->container->getParameter('name');
I hope this helps :)
Cheers!

Joomla: Is it possible to display a view of a component without iframe and plugin?

Is it possible to display a view of a component without iframe and plugin?
(That is to say, if possible with a few lines of PHP and maybe SQL queries?)
EDIT:
To be more clear: I'd like to do it directly in the PHP-Template!
(Would be fine to do it in an article as well, as I have written a
PHP-function showArticle(mixed $ident))
(I'm using Joomla 3.5)
I'd like to do something like
<jdoc:include type="component" view="example" name="position-x" />
or
<?php
show_component('component-name', 'view-name');
?>
you can use this component http://extensions.joomla.org/extension/components-anywhere
Install the plugin and enable it.
Then you can call the component this way {component url/of/the/component}
{component index.php?component=com_example&form=1}
Try to use non-sef urls in the url but sef url will still work.
There is another way to achieve this by calling the model into your controller file this way
JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_example/models', 'ExampleModel');
What this does is it searches the model class starting with ExampleModel in the folder specified. here you can eneter just a path string or array of the directories as the first parameter. Next you have to call the method inside the views file this way
$exmodel = JModelLegacy::getInstance('Something', 'ExampleModel', array('ignore_request' => true));
So here you create an instance of the class object which can be used to get the items from the model this way
$items = $exmodel->getitem();
$this->assignRef('items', $items);
next you can copy the default.php file in the tmpl folder of that component and place it anywhere you like inside your layout file. Basically instead of copying the entire component you are calling the model and getting the data which you can use in your layouts.

issue with passing variable from controller to view in codeigniter

This is my Code Of Controller
$datacc['user_id'] = $this->user_id;
$this->load->view("Templates/header",$this->data);
$this->load->view("Tax/Tax_Search",$datacc);
$this->load->view("Tax/Tax",$datacc);
in this, i want to pass "$datacc" to my both view files (Tax.php And Tax_Search)
but $datacc can't pass to Tax_Search.php file
can anyone help?
Thank You
You cannot call multiple view in one controller function.
This can be done in view file.
I suggest you that you should first create a template file and in that template call your views like this
template.php
$this->load->view("Tax/Tax");
$this->load->view("Tax/Tax_search");
<?php echo $content; ?>
$this->load->view("Tax/footer");
Let me know if you have queries

How to access language file inside config?

How we can use language file inside config.php php codeigniter?
I searched to find solution just from out side the config we can set item in config to use language file for setting config item value, but how we can set config item using language file inside config file?
for example i want to do as bellow:
$config['item'] = array(
'1' => $ci->lang->line('my_name')
);
You use wrong way. You try make view function in config file. You can make this in template or may be in model.
You should change your application architecture.
you can't access ci object in config file because this is load before CI_Loader class.
but you can update config.php field later on run time, using $this->config->set_item('key', 'value'); function in controller/model/library
sample code in controller __construct(){} method
public function __construct(){
$this->config->set_item('item', array('1' => $this->lang->line('my_name')));
}
Another way use hooks to update item globally, more detail available on CI documentation.

Call a php file from an action in zend framework

I have a requirement.In my indexAction() I want to call a php file e.g. verify.php. How can I do this? Do I need any changes in my application.ini file.
Please respond immediately.Thanks in advance.
In your action:
$this->_helper->redirector->gotoUrlAndExit('/mst/verify.php');
If your file exist e.g. '/mst/verify.php' then you have to do as #David Weinraub said.
But if it is virtual - you have to write own router in a bootstrap file for example and do as #David Weinraub said again.
First of all you should make a model, in the index method you make an instance of that object and call a defined method...

Categories