Pages

Saturday, September 10, 2016

Zend framework 3 Foundation 6

The Zend Framework 3 skeleton application comes with default 'bootstrap". So how should I change the theme using "Foundation 6".

At first download "Foundation 6"  into the "<project folder>/public" folder. "Foundation 6" installation can be done in several ways, Here I choose the npm installation because it will be easier to install "Grunt" & other related modules to install other related modules for 

  • Compile scss.
  • Minify css.
  • Concatenate javascript.
  • Minify Javascript.

The best way to manage locally installed npm packages is to create a package.json file.
To create the "package.json" follow instructions here. Only thing that you have to make sure is the main file name is "Gruntfile.js". Now you are ready to install "Foundation 6". The following command will install the "Foundation 6".

$ npm install foundation-sites --save

It will install "Foundation 6" into the "<project folder>/public/node_modules/foundation-sites" folder. 

Now you just need to edit just only a single file. 
Open the "<project folder>module/Application/view/layout/layout.phtml". 

Chang the following line
        <?= $this->headLink(['rel' => 'shortcut icon', 'type' => 'image/vnd.microsoft.icon', 'href' => $this->basePath() . '/img/favicon.ico'])
                        ->prependStylesheet($this->basePath('css/style.css'))
                        ->prependStylesheet($this->basePath('css/bootstrap-theme.min.css'))
                        ->prependStylesheet($this->basePath('css/bootstrap.min.css'))
        ?>
 into 
        <?= $this->headLink(['rel' => 'shortcut icon', 'type' => 'image/vnd.microsoft.icon', 'href' => $this->basePath() . '/img/favicon.ico'])
                        ->prependStylesheet($this->basePath('css/style.css'))
                        ->prependStylesheet($this->basePath('node_modules/foundation-sites/dist/foundation.min.css'))
        ?>

And

        <?= $this->headScript()
            ->prependFile($this->basePath('js/bootstrap.min.js'))
            ->prependFile($this->basePath('js/jquery-2.2.4.min.js'))

        ?>

Into
        <?= $this->headScript()
            ->prependFile($this->basePath('js/jquery-2.2.4.min.js'))
            ->prependFile($this->basePath('node_modules/foundation-sites/dist/foundation.min.js'))

        ?>

Finally, add the following code before the end of the </body> tag.

<script> $(document).foundation(); </script>

Sunday, July 3, 2016

Zend Framework 3 developer mode "Undefined index: db"

Ones enabling the developer mode in Zend Framework 3 you may get the fallowing error.

Notice: Undefined index: db in /var/www/html/zf3/vendor/zendframework/zend-db/src/Adapter/AdapterServiceFactory.php on line 27

To get rid of this setup the db configuration in "config/autoload/global.php" as fallows

return [
    'db' => [
        'driver' => 'Pdo',
        'dsn'    => 'mysql:dbname=zf3;host=localhost',
    ],    // ...
];


Saturday, August 17, 2013

Revision Controling using Git Part I

Creating a Git repositay

revision controlling or version controlling is a very important thing in modern software development. To know more about it's importance read the fallowing article at oss watch.
                                 Initializing and using Git is easier than expected. At first Git must be installed to computer. Second, User identity should be set as fallows

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

Third, create a file called ".gitignore" at the root of the project. Open the file and add folder paths that should not be included into the Git repository. Paths should be as started from project root directory.

Forth, initialize it repository by executing
        $ git init
Fifth, Add all necessary files to the git repository
        $ git add .
Finlay , Commit
        $ git commit -m "<your message>"

Thats it, If all are done properly 

resourcess

http://git-scm.com/book/en/Git-Basics-Getting-a-Git-Repository
http://git-scm.com/book/en/Getting-Started-First-Time-Git-Setup
http://symfony.com/doc/current/cookbook/workflow/new_project_git.html

       

      

Sunday, July 14, 2013

Creating forms in Symfony2 part III

I had created a "one to many " relation and a form related to them. Today I am going to create a "many to many " relation and there forms. I will use these forms to create a "User loging" in my next blog post.

OK, my relationship is simple, I take 'user' and 'role'. a user may have zero or many roles and a role mayhave zero or many users. (This diagram does not shows the zero or many relationship ).



Create 'User' and 'Role' entities by executing 
$ php app/console generate:doctrine:entity
command. (keep in mind configuration format should be in "xml" format for this tutorial)

then entity configuration files should be updated. 
first open the 
<my bundle>/Resources/config/doctrine/User.orm.xml file and add fallowing to the file inside the <entity></entity> tags.

<many-to-many field="role" inversed-by="user" target-entity="Acme\<my bundle>\Entity\Role">
<join-table name="UserRole">
<join-columns>
<join-column name="userId" referenced-column-name="id" />
</join-columns>
<inverse-join-columns>
<join-column name="rolrId" referenced-column-name="id" />
</inverse-join-columns>
</join-table>
</many-to-many>

then 
open the 
<my bundle>/Resources/config/doctrine/Role.orm.xml file and add fallowing to the file inside the <entity></entity> tags.


<many-to-many field="user" mapped-by="role" target-entity="Acme\<my bundle>\Entity\User"/>


then update the entities by executing 
$ php app/console generate:doctrine:entities <my bundle>
get more information about doctrine many to many relationships from here.

update the database 
$ php app/console doctrine:schema:create or
$ php app/console doctrine:schema:update

Now entities creation is completed. Now CRUD should be created. Do these using 
$ php app/console doctrine:generate:crud

command for both User and Role entities.
Now few changes should be done to forms. For the 'Role' form actually it shouldn't have a option to select user even it was designed for it. But for the User entity it should have a  multiple select filed for select user's role's

if the CRUD creation was executed correctly file called
Acme/<my bundle>/Form/RoleType.php was generated with some php code.
inside the RoleType class there is a method named buildForm. inside this
field options is add to the $builder instance.

it is looks like that

$builder
->add('name')
->add('role')
->add('user');;

no need to display users, remove that 
->add('user');;

finally it looks like 
$builder
->add('name')
->add('role')

then open the 
Acme/<my bundle>/Form/UserType.php  file update the $builder instance inside the BuildForm method.

it is looks like

$builder
->add('username')
->add('salt')
->add('password')
->add('email')
->add('isActive')
->add('role')


role field need to be populated with roles from the "Role". to do this edit it as fallow.


$builder
->add('username')
->add('salt')
->add('password')
->add('email')
->add('isActive')
->add('role','entity',array(
'class' => 'AcmeAuthBundle:Role',
'property' => 'name',
'multiple' => TRUE
))










Monday, June 24, 2013

Creating forms in Symfony2 Part II

We have created blog user level form, Now we have to create User. user has 'name', 'display name','e mail', 'image id' and 'blog user level id'. According to our ERD one user has one blog user level, one user level has many Users. To create the user form let's begin with creating entity by running
$ php app/console generate:doctrine:entity
and create 
'name', 'display name','e mail', 'image id' files.  Now we have to create 'blog user level id' field. I still couldn't find a way to create relations in command prompt. But i found a way to do it by editing entity configuration file. open the 'BlogUser.orm.xml' file and add fallowing

    <many-to-one field="bloguserlevel" target-entity="Acme\UserBundle\Entity\BlogUserLevel">
        <join-column name="blog_user_level_id" referenced-column-name="id"/>
    </many-to-one> 


final file looks like this

<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
  <entity name="Acme\UserBundle\Entity\BlogUser">
    <id name="id" type="integer" column="id">
      <generator strategy="AUTO"/>
    </id>
    <field name="name" type="string" column="name" length="255"/>
    <field name="displayName" type="string" column="display_name" length="255"/>
    <field name="email" type="string" column="email" length="255"/>
    <field name="image" type="integer" column="image"/>
    <many-to-one field="bloguserlevel" target-entity="Acme\UserBundle\Entity\BlogUserLevel">
        <join-column name="blog_user_level_id" referenced-column-name="id"/>
    </many-to-one>      
  </entity>
</doctrine-mapping>


then create entity by executing
$ php app/console generate:doctrine:entities AcmeUserBundle




update the database
$ php app/console doctrine:schema:update --force

Create CRUD operations
$ php app/console generate:doctrine:crud

We have a drop down(blog_user_level_id) in this form. To load the user levels open the
Acme/UserBundle/Form/BlogUserType.php for and update buildForm() method. the method will be looks like as fallows

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('name')
            ->add('displayName')
            ->add('email')
            ->add('image')
            ->add('bloguserlevel','entity',array(
                    'class' => 'AcmeUserBundle:BlogUserLevel',
                    'property' => 'name',
            ))
        ;
    }


thats it. goto http://localhost:8000/bloguser/ in check the form is working..







Tuesday, May 28, 2013

Creating forms in Symfony2 Part I

Symfony2 command line tool has provided a excellent way to create forms without too much bother about the code.
 
  Now i am going to create all forms(CRUD) for "blog_user_level" table. Guess how much time will I spend for it. OK  keep that in your mind.

First of all i create entity for the "blog_user_level" to do that run fallowing command in the terminal.

     $ php app/console generate:doctrine:entity

then it will ask fallowing parameters.

    The Entity shortcut name: AcmeUserBundle:BlogUserLevel
    Configuration format (yml, xml, php, or annotation) [annotation]: xml
    New field name (press <return> to stop adding fields): name
    Field type [string]:
    Field length [255]:

    New field name (press <return> to stop adding fields): level
    Field type [string]: integer

    New field name (press <return> to stop adding fields):

    Do you want to generate an empty repository class [no]?


    Do you confirm generation [yes]? 


then update the database
    $ php app/console doctrine:schema:update --force
now we want to create crud. to do that
    $ php app/console generate:doctrine:crud --overwrite

then it will ask some parameters

    The Entity shortcut name: AcmeUserBundle:BlogUserLevel
    Do you want to generate the "write" actions [no]? yes
    Configuration format (yml, xml, php, or annotation) [annotation]: xml
    Routes prefix [/bloguserlevel]:

    ...........


  
Sometimes it will ask to update routing.yml file. yeh that's all.
now go to the http://localhost:8000/bloguserlevel/ and test CRUD application.







Creating a bundle in Symfony2

Overview
    Learning with a sample project is a best way to learn a project. Here I am going to create a blog system. Here is my ERD. actually this is not mine, i have downloaded .mwb file from http://www.jarrodoberto.com and littlebit modification to it. thanks jarrod.


I have divided these into two separate section, user and blog. So i have to create to bundles. here i am going to crate "User" bundle.
  
Symfony2 command line tool provided a good support to developers. they don't need to create all file manual. just have to execute few commands in the terminal and will get a bundle easily.

open the terminal and change your directory to the project folder, then execute fallowing command

$ php app/console generate:bundle

then it will ask parameter one by one. in this time I create a bundle called "Document". the bundle will automatically be created inside the "src" folder.
and the bundle must be located inside the "Acme" folder and it's name must be ended with suffix "Bundle". at this time command line tool ask  namespace value, here it is "Acme/UserBundle". then it will ask as fallows

Bundle namespace: Acme/UserBundle
Bundle name [Acme
UserBundle]:
Target directory [/var/www/kanasblog/src]:
Configuration format (yml, xml, php, or annotation): yml
Do you want to generate the whole directory structure [no]? Yes
Do you confirm generation [yes]? Yes
Confirm automatic update of your Kernel [yes]?
Confirm automatic update of the Routing [yes]?
 

default values has shown inside the squire brackets.

thats it.. the bundle has generated now. to check that open the fallowing url in your browser

 http://localhost:8000/hello/kanasblog

it should display "kanasblog" in the browser..