Kohana 3.2 not working Form helper - php

I have some code, where is used Form helper. All worked well. Now I have error
Call to undefined method Form::open()
When I check SYSPATH exist classes Form and Kohana_Form
This situation is in each file where is used this helper.
This is kohana 3.2. In this files was not any changes. I tried it on PHP 5.4 and PHP 5.5
Any idea why? Thanks in advance for help.

The most likely thing is that you have a Form.php somewhere that's overriding the SYSTEM Form.php. To find out if this is happening, use the Kohana::find_file() function like this:
Kohana::find_file('classes', 'form');
The output from this should tell you the path of the Form.php that's being used when you call the Form class. Check if it's the one in the SYSTEM folder.

Related

Easy way to find the controller file with only the URL on Cake PHP

Being new to Cake on PHP, I am trying to work out if I have a URL, what would be the easiest way to find the controller code for it?
The URL on my local machine is something like:
http://foofoofoo.local/protected/admin/org/edit/1
I have worked out that the location of the view for this file is at this location on my machine:
/var/www/MyApp/protected/app/views/org/admin_edit.ctp
I thought what I'd do is do a search throughout the entire codebase for anything referencing admin_edit.ctp. I found two entries, and changed them to see if I had found the point where the view is called, but despite changing the file name on these entries - the app still works when I visit the URL: http://foofoofoo.local/protected/admin/org/edit/1
I just want to see where the admin_edit.ctp file is being called within the site.
URL: http://foofoofoo.local/protected/admin/org/edit/1
This means I can assume you have a added a route in your /app/Config/routes.php. Where this is pointing can not be said since we don't have access to this file.
Why can I assume you have added this to your routes? Because the posted URL is not matching the CakePHP Conventions which clearly states that controllers should be defined in plural. Since the URL will be accessing the Controller directly through the Controller, unless a route has been specified, I know that the OrgController does not exist. Why?
Try Inflector::pluralize('Org'). It will return 'Orgs' to you. And thus meaning the controller should be called OrgsController and you should be accessing this Controller via the following URL.
http://foofoofoo.local/protected/admin/orgs/edit/1
In this OrgsController there should be an action (function) called admin_edit(), because you have prepended the org with Admin, which is a prefix.
It can be possible that the /protected part, is part of the URL as well, but do not know where your main /App is located and what part of the URL is pointing to the /app/webroot/index.php file.
The Views can be found at /app/View/Orgs/*.ctp.
If you are still having trouble finding your files. Please start with the Blog tutorial written by the Cake Community. This tutorial describes all the neat built-in tricks and will get your first app running in no-time. Please read that first!
If you are still having trouble, feel free to update your question and add the /app/Config/routes.php file.
Under Cake 1.3, if your application has an AppController (check if the file app/app_controller.php exists), you can put this code in the beforeFilter method:
debug($this->params);
It will print an array on your app pages when you are in debug mode, with the name of the controller and the action used.
Array
(
...
[controller] => controller_name
[action] => action_name
...
)
If the AppController does not contain any beforeFilter method, you can just create it:
function beforeFilter()
{
debug($this->params);
}

HTMLHelper addCrumb method not available

I would like to use the addCrumb method in my Layout to automatically add controller links. I tried this but the Html-Helper-Object in the Layout didn't contain the addCrumb Function. Then I tried to use the function in the beforeFilter in my AppController to set the Link but this wont work too (no error given). At last I tried to use an element to make this happen, but this didnt the job (error method not found).
I am using CakePHP 2.0 - has anybody an idea to solve my problem (without changing the *.ctp files by hand)?
PS: Using $this->html->addCrumb() in my specific .ctp-file works great.
To have access to HTML helper methods such as addCrumb, you must make sure the helper is loaded for whatever action you want to use it in. Simply do $this->helpers[] = 'Html'; in your controller (in an action or in your AppController to add it universally).

change configure variable dynamically cakephp

Let's say I have this in my bootstrap.php file in a cakePHP application:
Configure::write('Config.language', 'eng');
How can I dynamically change the value of that configuration variable based on user action in a controller of my application? I tried to do the same thing that I did above here in my controller, but that didn't work
Any help?
Try Configure::write('Config.language', 'dut'); for e.g.
This answer from the question suggested by #Ryan Pendleton shows a somewhat correct way to use this directive.
It should be used in the AppController because it gets loaded first - as the parent of all other controllers in the application itself.
I used "somewhat correct" because it is best to validate the language codes ('eng', 'fre', 'dut') in the app/config/routes.php file - go here for more information.
Also do check out this: Internationalization-Localization explanation.

Symfony subdirectory lib/form/<new_directory>

I am going to program a website in symfony 1.4. It is working very fine. But I have on question.
How can access to a subfolder in lib/forms/
Example:
I have an accountForm.php in
/lib/forms/account/accountForm.php
How can I get to this in the template and in action, when my module is called "account".
I can include the accountForm.php pretty good, when I am putting it in
/lib/forms/accountForms.php
But I want it the other way to have more overview. Can somebody help me?
Well part of the issues is probably that you havent named the file properly... it should be AccountForm.class.php if it is an actual form class. As long as it is named that way it should autoload just fine. Just make sure you clear cache after you have added a new file.
If its not a class then it doesnt belong in a lib directory. That exactly is in accountForm.php?
You might also want to customize you autoloading configuration if you are sure of what youre doing: http://www.symfony-project.org/reference/1_4/en/14-Other-Configuration-Files
I'm not sure but try adding the form's path to autoload.yml
yourProject/config/autoload.yml
use %SF_MODEL_LIB_DIR%/forms if the form is in lib/model/forms
or %SF_LIB_DIR%/forms if the form is in lib/forms
autoload:
customForm:
name: yourForm
path: %SF_MODEL_LIB_DIR%/forms/accounts/
recursive: on
Name the account form accountForm.class.php and then in your action you can just do:
$this->form = new accountForm();
and in your template:
echo $form;

How can I bootstrap Symfony into a standalone script?

(I hope 'bootstrap' is the correct term...)
I have a Symfony 1.4 project in which I'm using a PHP script that mostly contains Javascript (I'm including this script with a simple <script src="/js/myStuff.js"></script> tag). I need to use some Symfony classes, helper methods, and variables from within the script (specifically the sfConfig class, url_for() helper method, and the $sf_request variable.) I'm at a loss as to how to achieve this. I tried copying the code from one of the front controllers into the script, but that ended up outputting the contents of my application's layout file.
Thanks in advance!
You can do what you want by using something like this to create a symfony context:
require_once($_SERVER['DOCUMENT_ROOT'].'/../config/ProjectConfiguration.class.php');
$configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'prod', false);
$context = sfContext::createInstance($configuration);
To use url_for, you will also need to either load/include the Url helper, which can be done like:
sfContext::getInstance()->getConfiguration()->loadHelpers('Url');
I think there's a better approach though:
Serve this javascript file as symfony action if you need access to symfony - there's nothing that says you can only serve html through symfony.
Check out the block here entitled Javascript As An Action for an explanation ...
http://www.symfony-project.org/jobeet/1_2/Doctrine/en/18#chapter_18_user_feedback

Categories