I'm in the day 10 of Symfony's Jobeet Tutorial. Everything worked good, but when I tried to go to the index page: http://localhost:9090/frontend_dev.php
I got the following message:
sfPatternRouting Match route "job" (/job.:sf_format) for /job with parameters array ( 'module' => 'job', 'action' => 'index', 'sf_format' => 'html',)
2 Info sfFrontWebController Action "job/index" does not exist
3 Error sfError404Exception Action "job/index" does not exist.
(I still have a backup of day 9, and the index page works fine).
Any suggestions?
I guess you have replaced the methods in app/modules/job/actions.class.php with what you found on day 10, instead of simply adding them. There must be an executeIndex() method in this file if you want to get something in /job
Yeah, it's something like this:
class jobActions extends sfActions
{
public function executeIndex(sfWebRequest $request)
{
$this->categories = Doctrine_Core::getTable('JobeetCategory')->getWithJobs();
}
public function executeShow(sfWebRequest $request)
{
$this->job = $this->getRoute()->getObject();
}
public function executeNew(sfWebRequest $request)
{
...
}
...
}
I also had overwrite it. Yeah so executeIndex and executeShow are important for "index" and "show". ;)
Related
First of all, I am moving from Symfony 1.4 to Symfony 3. (Yes, I was kicking and screaming at first)
My Question: I am running a manual query from the following FormType class that is for a chunk of my Signup form. I am moving the Address part of the signup into its own class. I am calling a geographical table to get my states list and I have a Union... hence this is why I am not calling an entity class.
The problem is that I need to connect to the database but cannot because it's an Abstract class. If I run this in the Controller Class, no problem, but can't do it herein this Abstract class. I have a bunch of manual steps to go through before making any inserts, so I can just
How do you make the following work? I have not created any services, but if I put all of this into a controller class, then it works fine.
<?php
namespace LocationBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Doctrine\ORM\EntityManager;
class PartialAddressType extends AbstractType
{
private function getStatesList()
{
$sql = "
SELECT
'0' AS id
,'' AS name
,'' AS abbreviation
,'Select State' AS display
UNION
SELECT
id
,trim(name)
,trim(abbreviation)
,CONCAT(trim(abbreviation), ' - ', trim(name)) AS display
FROM
geo_state
WHERE
type = 'state'
ORDER BY abbreviation ASC; ";
$manager = $this->getDoctrine()->getManager('default');
$conn = $manager->getConnection();
$rs = $conn->query($sql)->fetchAll();
return $rs;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$rs = $this->getStatesList();
// This one is for a Select
$builder->add('locationState', ChoiceType::class, array(
'expanded' => FALSE,
'multiple' => FALSE,
'choices' => $rs(),
'choice_label' => $rs['display'],
'choice_attribute' => $rs['abbreviation'],
'preferred_choices' => array('TX'),
'choices_as_values' => FALSE,
'label' => 'State',
)
);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array());
}
public function getName()
{
return 'location_bundle_partial_address_type';
}
}
I suggest you following steps:
1) Move the query in a separate repository class (I hope you map the table as an entity)
2) Use an EntityType Field with the Custom query as described here
3) Avoid the UNION using the placeholder
Last tips, You should implements the getBlockPrefix method instead of getName as described in the migration guide here.
Hope this help
I'm upgrading my app from ZF-1.12 to ZF-2.4.
I' have this login controller:
class LoginController extends AbstractActionController {
public function indexAction() {
$this->layout('login/layout');
return new ViewModel(array(
'form' => 'some-form-object',
));
}
}
The thing is, the view seems to be rendered without the selected layout.
However, when I comment out the 'return new ViewModel'.. everything works as expected.
What am I doing wrong?
Many thanks.
Apparently 'form' is sensitive word, when changing the var name - it worked.
I have three urls:
localhost:8000/oc/online-marketing/ppc
localhost:8000/websystems/online-marketing/ppc
localhost:8000/all/online-marketing/ppc
and I need dynamic settings for each URL.
Before that, I've used to have the route.php like this:
Route::get('oc/online-marketing/ppc', function()
{
$users = User::where('client_id', 1)->get();
return View::make('users')->with('users', $users);
});
But I must set dynamic url like this: Route::get('{project}/{module}/{submodule}', ... );
where project is oc or websystems or all
The module is online-marketing
The submodule is ppc
The project name oc, websystems or all could be in table named users
How can I achieve that by using controllers?
You may try something like foillowing, declare the Route like this:
Route::get('{project}/{module}/{submodule}', array('as' => 'mycontroller.project', 'uses' => 'MyController#project'));
Create the Controller:
class MyController extends BaseController {
public function project($project, $module, $submodule)
{
//...
}
}
Here's something to get you started with ...
In your routes.php file, you can have something like:
Route::get('/{clientID}', array('uses' => 'SomeController#someFunction'));
And in the SomeController.php file:
public function someFunction($clientID)
{
$users = User::where('client_id', $clientID)->get();
return View::make('users')->with('users', $users);
}
For more information, refer to http://laravel.com/docs/routing#route-parameters
Hello I am having some difficulty setting up a RESTful routing for a login controller. I keep getting hit with a status 404. Here is what I have so far. Any ideas?
In my routes:
'login' => array(
array('GET', new Route('session/login')),
array('POST', new Route('session/login'))
),
And in my sessions controller I have:
class Controller_Session extends Controller_Template {
public function get_login(){
return View::forge('session/login');
}
public function post_login() {
return View::forge('session/login',$data);
}
}
Try it using the default routing and the Rest controller.
class Controller_Session extends Controller_Rest
{...}
Delete the routes you set up and try accessing the Controller using {url}/session/login
basically delete all routes you have created.
Then create a controller session.php:
class Controller_Session extends Controller_Rest
//class Controller_Session extends Controller_Hybrid
{
public function get_login()
{
return View::forge('session/login');
}
public function post_login()
{
return View::forge('session/login',$data);
}
}
You can extend Controller_Hybrid, if you want to access to both rest and non-rest methods.
Now try with jquery to access url: '/session/login'
It should work!
Good luck
It was an Apache error. The mod rewrite module was not activated on a Debian Based OS
I want create a custom element and use the short name for add the element into Form, using the new ServiceManager tecnique for ZF2 V.2.1+
I am try to copy the same sample of the zend documentation step to step but it not works.
When I use the service writting the short name, it raises a exception because service not found:
Zend\ServiceManager\Exception\ServiceNotFoundException
File:
Zend\ServiceManager\ServiceManager.php:456
Message:
Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for Test
I think I have all classes identically, see follows
This is my custom element:
namespace SecureDraw\Form\Element;
use Zend\Form\Element\Text;
class ProvaElement extends Text {
protected $hola;
public function hola(){
return 'hola';
}
}
This is my Module.php I have my invokable service be able to use short name:
class Module implements FormElementProviderInterface {
//Rest of class
public function getFormElementConfig() {
return array(
'invokables' => array(
'Test' => 'SecureDraw\Form\Element\ProvaElement'
)
);
}
}
In my form I use for add the element, the commented line works ok, but with short name not works:
$this->add(array(
'name' => 'prova',
//'type' => 'SecureDraw\Form\Element\ProvaElement',
'type' => 'Test', //Fail
));
In my action:
$formManager = $this->serviceLocator->get('FormElementManager');
$form = $formManager->get('SecureDraw\Form\UserForm');
$prova = $form->get('prova');
echo $prova->hola();
The problem is that the elements created via FormElementManager have to be created into init method instead __Construct method how it can see in this page.
The zend documentation is badly explained
Workaround:
In your own module, create the following two files:
FormElementManagerConfig with the invokables short names of your custom form elements;
Subclass Form\Factory and override getFormElementManager and pass the config to the FormElementManager constructor;
You then use your own Factory to create your Form, like this (you can pass a very rudimentary, e.g. empty array, or a more or less full-fledged $spec to $factory->createForm()):
$factory = new Factory();
$spec = array();
$form = $factory->createForm($spec);
FormElementManagerConfig.php:
class FormElementManagerConfig implements ConfigInterface
{
protected $invokables = array(
'anything' => 'MyModule\Form\Element\Anything',
);
public function configureServiceManager(ServiceManager $serviceManager)
{
foreach ($this->invokables as $name => $service) {
$serviceManager->setInvokableClass($name, $service);
}
}
}
MyFactory.php:
class Factory extends \Zend\Form\Factory
{
public function getFormElementManager()
{
if ($this->formElementManager === null) {
$this->setFormElementManager(new FormElementManager(new FormElementManagerConfig()));
}
return $this->formElementManager;
}
}