Showing posts with label GitHub. Show all posts
Showing posts with label GitHub. Show all posts

Monday, January 11, 2016

CPANAGeneratorBundle

I was looking for a CRUD generator able to do more than the one from Sensio Labs, this is how I found PUGXGeneratorBundle.

PUGXGeneratorBundle is extending SensioGeneratorBundle and very important has decent documentation. Some of the  functionalities I like from it:
  • support for form themes (customizable)
  • default templates suitable with Boostrap and Font Awesome
  • nice "check" icons for boolean fields (when using Font Awesome)
  • support for pagination (requires KnpPaginatorBundle)
  • support for filters (requires LexikFormFilterBundle)
  • support for sorting 
Of course I wanted something more so I made my own flavor of CRUD Generator.

CPANAGeneratorBundle adds to the Show view of an entity the associated objects from Bidirectional relations.
Example: there are 2 entities: Author and Book found in One-to-Many BIDIRECTIONAL relation. In 'Author' entity there is a property called 'books' of type ArrayCollection. In the author/show view after the fields related to Author there will be listed the Books associated. Also CPANAGeneratorBundle is adding buttons for Add book, view and edit.
Author
Last name: Herbert
First name: Frank
Nationality: American
Id: 1
Books
Add book
Title: Dune Chronicles
Genre : Science Fiction
Id:1
view edit
Title: Dune Mesiah
Genre: Science Fiction
Id: 2
view edit

You can find it on Github:  https://github.com/cristianpana86/GeneratorBundle
and on Packagist for installing via Composer:  https://packagist.org/packages/cpana/generator-bundle

Friday, September 25, 2015

cpana/basicblogbundle now on GitHub and Packagist

https://github.com/cristianpana86/BasicBlogBundle
https://packagist.org/packages/cpana/basicblogbundle
I've worked previously with GitHub, the new thing was to have the package on Packagist.com so it can be installed easily via Composer.
After creating my repository on GitHub I went on Packagist and created an account.
Following the instructions found on this article: http://www.sitepoint.com/listing-packages-on-packagist-for-composer/ I've created my composer.json document:

{
    "name":        "cpana/basicblogbundle",
    "type":        "symfony-bundle",
    "description": "Symfony Basic Blog Bundle",
    "keywords":    ["blog","symfony"],
    "homepage":    "https://github.com/cristianpana86/BasicBlogBundle",
    "license":     "MIT",
    "authors": [
        {
            "name": "Cristian Pana",
            "email": "cristianpana86@yahoo.com"
        }
   ],
   "require": {
       "php": ">=5.5.0",
       "symfony/symfony": "2.7.*",
        "doctrine/orm": "~2.2,>=2.2.3,<2.5",
        "doctrine/dbal": "<2.5",
        "doctrine/doctrine-bundle": "~1.4",
        "symfony/assetic-bundle": "~2.3",
        "symfony/swiftmailer-bundle": "~2.3",
        "symfony/monolog-bundle": "~2.4",
        "sensio/distribution-bundle": "~4.0",
        "sensio/framework-extra-bundle": "~3.0,>=3.0.2"
    },
    "minimum-stability": "dev",
    "autoload" : {
        "psr-4" : {
            "CPANA\\BasicBlogBundle\\" : ""
        }
    }
}

Some of the values are from the Symblog composer.json and may be outdated, it's something I have to look over.
I've added also the installation instructions on my GitHub repository and from there are automatically listed on Packagist.com:

Install using Composer:
    composer require cpana/basicblogbundle:dev-master
 
Register the bundle in AppKernel.php by adding:
    new CPANA\BasicBlogBundle\CPANABasicBlogBundle(),
 
Import paths in app/config/routing.yml by adding:
    CPANABasicBlogBundle:
    resource: "@CPANABasicBlogBundle/Resources/config/routing.yml"
 
Make sure to have configured your database in app/config/parameters.yml Generate you schema using console:
    php app/console cache:clear
    php app/console doctrine:schema:update --force

Thursday, July 9, 2015

PHP edit and save posts, delete posts - release v.04 on GitHub

For an Admin dashboard is more relevant to see just the titles (not entire content as in normal view) and have edit / delete buttons :

1. Admin dashboard for editing posts

- in the "render()" method of the class Blog, if the admin is logged, Edit button is displayed otherwise normal listing of posts
- new path /edit/{slug} added to route.xml as a result of the above

2. Edit posts and save them to database

- the edit post page should look exactly like the new post entry just that it should be populated with the values from DB. So I added the file "edit_post_entry.php" under templates.
Inside I added value=<?php echo '"'.$author.'"'; ?> (same for the title and category).
- issue:  I do not want to  take the file edit_post_entry.php and include it directly into the main template, I want first to process it (interpret ) with the local variables  replacing the actual "value=" in the HTML form.
The post "Read echo'ed output from another PHP file" http://stackoverflow.com/questions/631388/read-echoed-output-from-another-php-file showed me the way:

        ob_start(); // begin collecting output
        include 'myfile.php';
        $result = ob_get_clean(); // retrieve output from myfile.php, stop buffering
        //$result will then contain the text.


- as you could see the slug is used to identify  the post.Only for update I am using the post Id as unique identifier and the new slug is saved in database if the title of the blog is changed.

I will put in the form (edit_post_entry.php) a hidden field to store the post Id taken from database which will be used in the SQL update statement:

        $new_slug=SlugGenerator::slugify($Title);
        $stmt = $this->db->prepare("UPDATE blogposts SET Category=:field1, Author=:field2, ActualPost=:field3,title=:field4,slug=:field5 WHERE Id=:field_id;");
        $stmt->bindParam(':field_id',$PostID, PDO::PARAM_INT);
        $stmt->bindParam(':field1', $Category);
        $stmt->bindParam(':field2', $Author);
        $stmt->bindParam(':field3', $Text);
        $stmt->bindParam(':field4', $Title);
        $stmt->bindParam(':field5', $new_slug);
   

    $stmt->execute();


3. Delete posts   

First I get the post using  "getPost($post_slug)" and from the output the post Id is read and the delete is applied to that Id.

The code is available in my first release on GitHub, v0.4:  https://github.com/cristianpana86/myFrontController/releases/tag/v0.4



Thursday, July 2, 2015

GitHub


Now that I am preparing to develop the v0.4 I believe I should be using a version control software. After reading about the subject a little, and taking in account that many open source projects use GitHub I decided for it. Next steps were:

1. create account on GitHub
2. install GitHub for Windows
3. make Git work behind firewall at work. In the .gitconfig file, which on computer should be found  at %USERPROFILE% (Windows 7)I added this line:
        [http]
              proxy = http://<your-proxy>:<port>

Here details on how to find your proxy settings:  http://superuser.com/questions/346372/how-do-i-know-what-proxy-server-im-using

You can find my project on GitHub at this link:  https://github.com/cristianpana86/myFrontController