php - Loading incorrect url in Symfony -


can me please. each time enter url http://localhost/web/app_dev.php/activity1/ doesn't go page rather loads page http://localhost/web/app_dev.php/users/login. not seeing reason why it's doing that. after rewriting entity , controller.

entity

    <?php      namespace com\twcl\agripayrollbundle\entity;       /**      * activity1      */     class activity1     {         /**          * @assert\notblank(message="the activity type must entered.")          * @var string          *           */         private $activitytype;          /**          *           * @var string          *           *           */         private $activitydesc;          /**          * @assert\notblank(message="the activity date must entered.")          * @var \datetime          *           *           *          */         protected $activitydate;          /**          * @assert\notblank(message="the activity quantity worked must entered.")          * @var number          *       */     private $unitwork;      /**      * @var \datetime      *      */     private $dateentered;      /**      * @assert\notblank(message="the employee must entered.")      * @var integer      *       */     private $empid;      /**      * @var integer      */     private $transid;      /**      * @assert\notblank(message="the payroll period must entered.")      * @var \com\twcl\agripayrollbundle\entity\payrollperiod      */     private $payrollperiodid;       private $userid;      /**      * @assert\notblank(message="the section must entered.")      * @var \com\twcl\agripayrollbundle\entity\section      */     private $sectionid;     //@orm\joincolumn(name="description", referencedcolumnname="id")     /**      * @assert\notblank(message="the rate code must entered.")      * @var \com\twcl\agripayrollbundle\entity\rate      *       */     private $ratecode;     private $versionnumber;     private $verifystate;      public function getverifystate() {         return $this->verifystate;     }      public function setverifystate($state) {         $this->verifystate = $state;     }      public function setversionnumber($versionnumber) {         $this->versionnumber = $versionnumber;     }      public function getversionnumber() {         return $this->versionnumber;     }      /**      * set activitytype      *      * @param string $activitytype      * @return activity      */     public function setactivitytype($activitytype) {         $this->activitytype = $activitytype;     }      /**      * activitytype      *      * @return string       */     public function getactivitytype() {         return $this->activitytype;     }      /**      * set activitydesc      *      * @param string $activitydesc      * @return activity      */     public function setactivitydesc($activitydesc) {         $this->activitydesc = $activitydesc;     }      /**      * activitydesc      *      * @return string       */     public function getactivitydesc() {         return $this->activitydesc;     }      /**      * set activitydate      *      * @param \datetime $activitydate      * @return activity      */     public function setactivitydate($activitydate) {         $this->activitydate = $activitydate;     }      /**      * activitydate      *      * @return \datetime       */     public function getactivitydate() {         return $this->activitydate;     }      /**      * set unitwork      *      * @param integer $unitwork      * @return activity      */     public function setunitwork($unitwork) {         $this->unitwork = $unitwork;     }      /**      * unitwork      *      * @return integer       */     public function getunitwork() {         return $this->unitwork;     }      /**      * set dateentered      *      * @param \datetime $dateentered      * @return activity      */     public function setdateentered($dateentered) {         $this->dateentered = $dateentered;     }      /**      * dateentered      *      * @return \datetime       */     public function getdateentered() {         return $this->dateentered;     }      /**      * set empid      * @param integer $empid      * @return activity      *       *        */     public function getempid() {         return $this->empid;     }      /**      * empid      *      * @return integer       */     public function setempid($empid) {         $this->empid = $empid;     }      /**      * transid      *      * @return integer       */     public function gettransid() {         return $this->transid;     }      /**      * set payrollperiodid      *      * @param \com\twcl\agripayrollbundle\entity\payrollperiod $payrollperiodid      * @return activity      */     public function setpayrollperiodid(\com\twcl\agripayrollbundle\entity\payrollperiod $payrollperiodid = null) {         $this->payrollperiodid = $payrollperiodid;          return $this;     }      /**      * payrollperiodid      *      * @return \com\twcl\agripayrollbundle\entity\payrollperiod       */     public function getpayrollperiodid() {         return $this->payrollperiodid;     }      /**      * set userid      *      * @param \com\twcl\agripayrollbundle\entity\users $userid      * @return activity      */     public function setuserid(\com\twcl\agripayrollbundle\entity\users $userid) {         $this->userid = $userid;     }      /**      * userid      *      * @return \com\twcl\agripayrollbundle\entity\users       */     public function getuserid() {         return $this->userid;     }      /**      * set sectionid      *      * @param \com\twcl\agripayrollbundle\entity\section $sectionid      * @return activity      */     public function setsectionid(\com\twcl\agripayrollbundle\entity\section $sectionid = null) {         $this->sectionid = $sectionid;     }      /**      * sectionid      *      * @return \com\twcl\agripayrollbundle\entity\section       */     public function getsectionid() {         return $this->sectionid;     }      //protected $sectionidonly;      public function getsectionidonly() {         $id = null;         $section = $this->getsectionid();          if ($section!=null){             $id=$this->getsectionid()->getid();         }         return $id;     }      public function setsectionidonly ($empty) {      }      public function getfarmnameonly() {         return $this->farmnameonly;     }      protected $farmnameonly;      public function setfarmnameonly($farmname) {         return $this->farmnameonly = $farmname;     }      /**      * set ratecode      *      * @param \com\twcl\agripayrollbundle\entity\rate $ratecode      * @return activity      */     public function setratecode(\com\twcl\agripayrollbundle\entity\rate $ratecode = null) {         $this->ratecode = $ratecode;     }      /**      * ratecode      *      * @return \com\twcl\agripayrollbundle\entity\rate       */     public function getratecode() {         return $this->ratecode;     }      /**      * return activity string      * @return string      */     public function __tostring() {         return  strval($this->gettransid());     }      /**      * @assert\callback      * validation ensures: activities can entered days within payroll period.      */     public function constraint_within_payroll_period(\symfony\component\validator\context\executioncontextinterface $context) {          /* startdate<=activitydate<=enddate */         $startdate_diff = $this->activitydate->diff($this->payrollperiodid->getstartdate(), false);         $endate_diff = $this->activitydate->diff($this->payrollperiodid->getenddate(), false); //        var_dump($endate_diff); //        echo '<br/>'; //        var_dump($endate_diff->invert); //        echo' | '; //        var_dump($endate_diff->days); //        die();         if (                 ($startdate_diff->invert == 0 && $startdate_diff->days > 0) ||                 ($endate_diff->invert == 1 && $endate_diff->days > 0 )         ) {             $context->buildviolation('activities can entered dates within payroll period.')                     ->atpath('activitydate')                     ->addviolation();         }     }      /**      * @assert\callback      * validation ensures: duration of activity cannot go beyond 24hrs.      */     public function constraint_capped_duration(\symfony\component\validator\context\executioncontextinterface $context) {          if (                 strcmp(trim($this->activitytype), 'hourly') == 0 &&                 $this->unitwork > 24         ) {             $context->buildviolation('the duration of hourly activity cannot go beyond 24hrs.')                     ->atpath('unitwork')                     ->addviolation();         }     } } 

controller

    <?php      namespace com\twcl\agripayrollbundle\controller;      use symfony\component\httpfoundation\request;     use symfony\bundle\frameworkbundle\controller\controller;     use sensio\bundle\frameworkextrabundle\configuration\method;     use sensio\bundle\frameworkextrabundle\configuration\route;     use sensio\bundle\frameworkextrabundle\configuration\template;     use com\twcl\agripayrollbundle\entity\activity1;     use com\twcl\agripayrollbundle\form\activity1type;      /**      * activity1 controller.      *      * @route("/activity1")      */     class activity1controller extends controller     {          /**          * lists activity1 entities.          *          * @route("/", name="activity1")          * @method("get")          * @template()          */         public function indexaction()         {             $em = $this->getdoctrine()->getmanager();              $entities = $em->getrepository('comtwclagripayrollbundle:activity1')->findall();              return array(                 'entities' => $entities,             );         }         /**          * creates new activity1 entity.          *          * @route("/", name="activity1_create")          * @method("post")          * @template("comtwclagripayrollbundle:activity1:new.html.twig")          */         public function createaction(request $request)         {             $entity = new activity1();             $form = $this->createcreateform($entity);             $form->handlerequest($request);              if ($form->isvalid()) {                 $em = $this->getdoctrine()->getmanager();                 $em->persist($entity);                 $em->flush();                  return $this->redirect($this->generateurl('activity1_show', array('id' => $entity->getid())));             }              return array(                 'entity' => $entity,                 'form'   => $form->createview(),             );         }          /**          * creates form create activity1 entity.          *          * @param activity1 $entity entity          *          * @return \symfony\component\form\form form          */         private function createcreateform(activity1 $entity)         {             $form = $this->createform(new activity1type(), $entity, array(                 'action' => $this->generateurl('activity1_create'),                 'method' => 'post',             ));              $form->add('submit', 'submit', array('label' => 'create'));              return $form;         }          /**          * displays form create new activity1 entity.          *          * @route("/new", name="activity1_new")          * @method("get")          * @template()          */         public function newaction()         {             $entity = new activity1();             $form   = $this->createcreateform($entity);              return array(                 'entity' => $entity,                 'form'   => $form->createview(),             );         }          /**          * finds , displays activity1 entity.          *          * @route("/{id}", name="activity1_show")          * @method("get")          * @template()          */         public function showaction($id)         {             $em = $this->getdoctrine()->getmanager();              $entity = $em->getrepository('comtwclagripayrollbundle:activity1')->find($id);              if (!$entity) {                 throw $this->createnotfoundexception('unable find activity1 entity.');             }              $deleteform = $this->createdeleteform($id);              return array(                 'entity'      => $entity,                 'delete_form' => $deleteform->createview(),             );         }          /**          * displays form edit existing activity1 entity.          *          * @route("/{id}/edit", name="activity1_edit")          * @method("get")          * @template()          */         public function editaction($id)         {             $em = $this->getdoctrine()->getmanager();              $entity = $em->getrepository('comtwclagripayrollbundle:activity1')->find($id);              if (!$entity) {                 throw $this->createnotfoundexception('unable find activity1 entity.');             }              $editform = $this->createeditform($entity);             $deleteform = $this->createdeleteform($id);              return array(                 'entity'      => $entity,                 'edit_form'   => $editform->createview(),                 'delete_form' => $deleteform->createview(),             );         }          /**         * creates form edit activity1 entity.         *         * @param activity1 $entity entity         *         * @return \symfony\component\form\form form         */         private function createeditform(activity1 $entity)         {             $form = $this->createform(new activity1type(), $entity, array(                 'action' => $this->generateurl('activity1_update', array('id' => $entity->getid())),                 'method' => 'put',             ));              $form->add('submit', 'submit', array('label' => 'update'));              return $form;         }         /**          * edits existing activity1 entity.          *          * @route("/{id}", name="activity1_update")          * @method("put")          * @template("comtwclagripayrollbundle:activity1:edit.html.twig")          */         public function updateaction(request $request, $id)         {             $em = $this->getdoctrine()->getmanager();              $entity = $em->getrepository('comtwclagripayrollbundle:activity1')->find($id);              if (!$entity) {                 throw $this->createnotfoundexception('unable find activity1 entity.');             }              $deleteform = $this->createdeleteform($id);             $editform = $this->createeditform($entity);             $editform->handlerequest($request);              if ($editform->isvalid()) {                 $em->flush();                  return $this->redirect($this->generateurl('activity1_edit', array('id' => $id)));             }              return array(                 'entity'      => $entity,                 'edit_form'   => $editform->createview(),                 'delete_form' => $deleteform->createview(),             );         }         /**          * deletes activity1 entity.          *          * @route("/{id}", name="activity1_delete")          * @method("delete")          */         public function deleteaction(request $request, $id)         {             $form = $this->createdeleteform($id);             $form->handlerequest($request);              if ($form->isvalid()) {                 $em = $this->getdoctrine()->getmanager();                 $entity = $em->getrepository('comtwclagripayrollbundle:activity1')->find($id);                  if (!$entity) {                     throw $this->createnotfoundexception('unable find activity1 entity.');                 }                  $em->remove($entity);                 $em->flush();             }              return $this->redirect($this->generateurl('activity1'));         }          /**          * creates form delete activity1 entity id.          *          * @param mixed $id entity id          *          * @return \symfony\component\form\form form          */         private function createdeleteform($id)         {             return $this->createformbuilder()                 ->setaction($this->generateurl('activity1_delete', array('id' => $id)))                 ->setmethod('delete')                 ->add('submit', 'submit', array('label' => 'delete'))                 ->getform()             ;         }     } 

security.yml

# can read more security in related section of documentation # http://symfony.com/doc/current/book/security.html security:     # http://symfony.com/doc/current/book/security.html#encoding-the-user-s-password  encoders:     symfony\component\security\core\user\user:          algorithm: bcrypt         cost: 12      com\twcl\agripayrollbundle\entity\users:          algorithm: sha512         encode_as_base64: true  #            iterations: 5000                 # http://symfony.com/doc/current/book/security.html#hierarchical-roles     role_hierarchy:         role_view_data_owner_2: role_user         role_admin: role_user         role_super_admin: [role_user, role_admin, role_allowed_to_switch]      # http://symfony.com/doc/current/book/security.html#where-do-users-come-from-user-providers     providers:         administrators: #            entity: {class: comtwclagripayrollbundle:users, property: username}             entity: {class: comtwclagripayrollbundle:users} #        in_memory: #            memory: #                users: #                    user:  { password: $2a$12$s3ooyvnblwjquw.k76irookdhefhku4arydkg9cmlkszrcupvv3o2, roles: [ 'role_user' ] } #                    admin: { password: adminpass, roles: [ 'role_admin' ] }      # main part of security, can set firewalls     # specific sections of app     firewalls:         default:             anonymous: ~             http_basic: ~             form_login:                 login_path: /users/login                 check_path: /users/login_check                 csrf_provider: form.csrf_provider             logout:                 path: /users/logout                 target: activity_main                 invalidate_session: false                 delete_cookies:                      a: {path: null, domain: null}                     b: {path: null, domain: null}             anonymous: ~         # disables authentication assets , profiler, adapt according needs         dev:             pattern:  ^/(_(profiler|wdt)|css|images|js)/             security: false         # login page has accessible         demo_login:             pattern:  ^/demo/secured/login$             security: false          # secures part of application         demo_secured_area:             pattern:    ^/demo/secured/             # it's important notice in case _demo_security_check , _demo_login             # route names , specified in acmedemobundle             form_login:                 check_path: _demo_security_check                 login_path: _demo_login             logout:                 path:   _demo_logout                 target: _demo             #anonymous: ~             #http_basic:             #    realm: "secured demo area"      # these settings can restrict or allow access different parts     # of application based on roles, ip, host or methods     # http://symfony.com/doc/current/book/security.html#security-book-access-control-matching-options     access_control:         #- { path: ^/login, roles: is_authenticated_anonymously, requires_channel: https }         - { path: ^/login, roles: is_authenticated_anonymously}         - { path: ^/activity/main, roles: is_authenticated_anonymously} #        - { path: ^/activity/new, roles: role_user }          - { path: ^/activity, roles: role_user} 

routing.yml

comtwclagripayroll:     resource: "@comtwclagripayrollbundle/controller/"     type:     annotation     prefix:   / 

activity1repository

   <?php  namespace com\twcl\agripayrollbundle;  use doctrine\orm\entityrepository;   class activity1repository extends entityrepository {     public function findoverlappingwithrange(\datetime $startdate, \datetime $enddate)     {         $qb = $this->createquerybuilder('e');          $expr1 = $qb->expr()->andx('e.startdate < :enddate , e.enddate > :startdate');         $expr2 = $qb->expr()->andx('e.enddate > :startdate , e.startdate < :enddate');         $orexpr = $qb->expr()->orx($expr1, $expr2);          return $qb->andwhere($orexpr)             ->setparameter('startdate', $startdate)             ->setparameter('enddate', $enddate)             ->getquery()             ->execute()         ;     } } 

activitytype

    <?php  namespace com\twcl\agripayrollbundle\form;  use symfony\component\form\abstracttype; use symfony\component\form\formbuilderinterface; use symfony\component\optionsresolver\optionsresolverinterface;  class activitytype extends abstracttype {      protected $employeelist;     protected $formstate;      public function setemployeelist($emplist) {         $this->employeelist = $emplist;     }      public function getemployeelist() {         return $this->employeelist;     }      /**      * @param formbuilderinterface $builder      * @param array $options      */     public function buildform(formbuilderinterface $builder, array $options) {         $builder                 ->add('payrollperiodid', 'entity', array(                     'label' => 'payroll period',                     'class' => 'comtwclagripayrollbundle:payrollperiod',                     'query_builder' => function(\doctrine\orm\entityrepository $er) {                         return $er->createquerybuilder('p')                                 ->orderby('p.startdate', 'asc'); //                                ->where('p.state=1');                     }                         )                 )                 ->add('activitydate', 'datetime', array(                     'label' => 'activity date',                         /* 'data' => new \datetime() */                        )                 )                 ->add('empsearch', 'text', array('mapped' => false, 'label' => 'employee id', 'required' => false))                 ->add('empid', 'choice', array('label' => 'employee', 'choice_list' => $this->getemployeelist())                 )                 ->add('sectionsearch', 'text', array('mapped' => false, 'label' => 'section code', 'required' => false))                 ->add('sectionid', 'entity', array(                     'attr' => array('class' => 'activity_section_id_select_field'),                     'label' => 'section',                     'data_class' => null,//'com\twcl\agripayrollbundle\entity\section',                     'class' => 'comtwclagripayrollbundle:section',                     'query_builder' => function(\doctrine\orm\entityrepository $er) {                 return $er->createquerybuilder('s')                         ->innerjoin('s.farmid', 'f')                         ->addorderby('f.name') //                                ->addorderby('s.quadrant')                         ->addorderby('s.id')                 ;             }                         )                 )                 ->add('ratecode', 'entity', array(                     'label' => 'rate code & unit of measure',                     'class' => 'comtwclagripayrollbundle:rate',                     'query_builder' => function(\doctrine\orm\entityrepository $er) {                         return $er->createquerybuilder('r')                                 ->orderby('r.ratecode');                     }                         )                 )                 ->add('activitytype', 'entity', array('label' => 'activity type', 'class' => 'comtwclagripayrollbundle:acttype',)                 )                 ->add('unitwork', 'number', array('label' => 'units worked', 'required' => true,))                 ->add('activitydesc', 'text', array('label' => 'comments', 'required' => false))                 ->add('versionnumber', 'hidden')                 ->add('sectionidonly', 'hidden')                 ->add('farmnameonly', 'hidden'); //                ->add('dateentered', 'datetime', array('data' => new \datetime(), 'read_only' => true)) //                ->add('userid'); //        $builder->addeventlistener(\symfony\component\form\formevents::pre_set_data, function(\symfony\component\form\formevent $event) { //            $activity = $event->getdata(); //            $form = $event->getform(); // ////            if (isset($farm)) { // //            $form->add('sectionidonly', 'hidden') //                    ->add('farmnameonly', 'hidden'); ////            } //        });     }      /**      * @param optionsresolverinterface $resolver      */     public function setdefaultoptions(optionsresolverinterface $resolver) {         $resolver->setdefaults(array(             'data_class' => 'com\twcl\agripayrollbundle\entity\activity',             'cascade_validation' => true,         ));     }      /**      * @return string      */     public function getname() {         return 'com_twcl_agripayrollbundle_activity';     }  } 

in last row of security.yml telling symfony every url starting /activity requires user authenticated , have role_user.

if aren't authenticated redirected login page framework.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -