I'm upgrading a system from CakePHP 1.1 to CakePHP 1.3. In 1.1 I was able to use the HTML helper to do something like:
$html->input('User/email');
To get back data nested in:
$this->data['User']['email']
In the controller. Now I know that $html->input() has been replaced with $this->Form->input(). However, when I try to use:
$this->Form->input('User/email')
I get:
Undefined offset: 2 [CORE\cake\libs\view\helpers\form.php, line 496]
This is coming up because the / in the input. So it seems that 1.3 doesn't like using the / to specify the data should be returned nested. How might I achieve the equivalent of this in 1.3? Thank you much!
In 1.3 you would use
$this->Form->input('User.email');
To set an input for the User model and the email field.
If you have set up your form correctly though, you just need email
For example
$this->Form->create('User');
$this->Form->input('email');
$this->Form->end('Submit');
But in short, to answer your specific question, replace the / with a .
Related
I'm from ASP.NET MVC background and this is first time I'm trying to write something in PHP.
In ASP.NET MVC we can develop models for our data and using the actions that we write we can get them or send them to another action. What I mean is that
public ActionResult Login_Action(LoginModel _Model) {
// Authenticating the user
return RedirectToAction(X);
}
when calling this the url that is shown in the address bar (in case of using GET, if it is POST nothing will be shown after the page name) will be:
www.WebsiteX.com/Login?Username=something&Password=something
The problem is that I don't even know how search for this in google (like by typing what exactly) because in Microsoft side, these are handled automatically the way I described.
But in case of PHP, how can I get the values in the address bar? do I have to get the actual address and then break the values down into arrays?
I'd appreciate any help.
First of all, this seems to be invalid for me: www.WebsiteX.com/Login?Username=something?Password=something The first parameter need to be ? and the others should be &.
Second: You can get your values of your parameters by accessing the $_GET global array.
Eg. for the username echo $_GET["Username"];
Are you using any framework? You should. And then, the Framework will give you the way to do that. In ASP.NET you use a Framework so do the same in PHP.
With vanille PHP you can get the GET values with $_GET['Username']. But please, use a framework.
I think that the most popular are Laravel and Symfony right now.
Example:
In laravel you can bind a parameter to a variable so you can do something like:
//Url: mywebsite.com/user/1/
Route::get('user/{id}', function($id)
{
return 'User '.$id;
});
Which is similar with the ASP.NET example.
I am writing import script from csv files and I need to validate data, most of the data is strings so I want to use something like Jinput to sanitize it.
Is there is something Joomla already have for this purpose?
It would be ideal to have something like
$field = JSanitizer::get($data/*array with data*/, "fieldname"/*name of field*/,
'string'/*type of data*/, 'null'/*default value*/);
Also I would need it to work both in Joomla 2.5 and 3.0 versions.
You are probably looking for JFilterInput::clean() This would work as follows:
$field = JFilterInput::clean($data[$fieldname], 'filter');
This does not give a way to set a default value, so you would have to handle that afterwards. This should be the same filtering that is typically done with JInput as well as on JForm elements if you write custom components.
I can't seem to find a good list of all the filters, but you can see an old version of the source here: http://docs.joomla.org/API16:JFilterInput/clean. Most recent version of the function starts at line 162 here: https://github.com/joomla/joomla-cms/blob/master/libraries/joomla/filter/input.php
Note also that you want to pull the field out of the data array yourself. You can actually send it the entire array without a filter setting and it should at least check the entire array for XSS and other issues. If you want more nuanced filtering for integers and such, it would best to do it field by field.
$field = JFilterInput::clean($data[$fieldname], 'filter');
will fire a notice
"Non-static method JFilterInput::clean() should not be called statically"
You should initiate this with JFilterInput::getInstance() first and call it dynamically e.g.:
$field = JFilterInput::getInstance()->clean($data[$fieldname], 'filter');
Tom
You should read Joomla docs and use something like this before parsing file : $string = JRequest::getString( 'description' );
This should work across all version since 1.5
There has been some github projects to implement html purifier as plugin, i found this, but havent chance to tested it, but it should work though.
Hi I've got an error in my Zend Framework project...
It raised:
Invalid controller specified (myweb)
Here is my apache error.log:
PHP Warning: Invalid argument supplied for foreach() in /var/www/myweb/application/layouts/scripts/layout.phtml on line 107
Here's my code in layout.phtml:
<?php foreach($this->category as $categories):?>
<li><div id="sidemenu"> �<?php echo $categories['categoriesName'];?></div></li>
<?php endforeach;?>
Can anybody help me?
The problem seems to be that for some reason your url is presenting myweb as the controller instead of what should be your controller.
My guess is the you are trying to use localhost to display your application so are presenting a url similar to http://localhost/myweb/...
While it is possible to use the localhost to view ZF applications it often becomes inconvenient as applications become more complex. I would suggest you use a vhost for anything more then a very simple application.
I'm pretty sure that when you resolve the url problem the php warning will likely fix itself.
It seems like the variable $this->category is not set in the Controller. You can do this by defining $this->view->category from your controller.
Mostly when using these controller generated variables in the layout script instead of the corresponding view script, you want to use the same data in every view. If this is the case, check this question: Sending variables to the layout in Zend Framework
This error come because your array $this->category is blank. if this is blank array or return nothing then how foreach loop will execute?
so first print this array and check.
I'm using Symfony2 and Doctrine 2.
I created a form in Symfony2. But I am not able to get the posted values in the controller. The syntax I use to get the values is:
$block = $request->request->get('txtblock');
You should try to use a var_dump() on $request->request->all(). That way, you can debug what has been send. Most likely, your form/input field has a different name.
You can try to print the content of $_POST. It's not the way Symfony is designed to be, but if $_POST is empty too, I guess the problem is on your form submission.
Using CakePHP 1.3, I post a form which correctly fills in $this->data. According to the docs, it seems like $this->params['form'] should be populated with some information as well, but it's simply an empty array. Is there a particular reason for that?
The form is built using the Form Helper, as follows...
Some relevant code:
$default_form_create_options = array(
'inputDefaults' => array(
'label'=>false,
'div'=>false
)
);
echo $form->create('Preappform', $default_form_create_options);
// --- snip, a bunch of form elements created via $form->input()
echo $form->end(array('label'=>'Send This Form »', 'class'=>'submit-button', 'escape'=>false));
I know that the form data is available in $this->data, so maybe this is just a documentation/curiosity issue. If so... my bad.
Just for giggles try $this->params['data']. I don't know why but for some reason it shows form data in there for me.
The documentation has conflicting data as you can see here http://book.cakephp.org/view/972/data. I am guessing that if you use the FormHelper it will show up in $this->data and if you don't use the FormHelper it will show up in $this->params['form'].
Notice if you use FormHelper the name of the element will be data['Model']['element_name'] and if you just create the form manually you can name it 'element_name'. By doing the later I believe it throws it into the params['form'] instead of the $this->data.
I too faced the same while working with CakePHP 1.3. Later I solved the issue by using the $this->params['data']. But I have some questions, I'm a newbie to cakephp and using the manual as my reference, it seems that the manual is not at all updated, while searching about this issue, I found out that it was working well in earlier versions and after 1.2, it is not at all there in Cakephp. Is there any CakePHP experts to clarify this stuff ?
Not necessarily related to Cake, but the answer to the problem when I had it: if you're including a file upload in your POST, double-check that the file you're uploading isn't larger than the limit specified in your php.ini file.