SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb What Libraries and script you prepare for new PHP Project

    Hello everyone;

    I always wandered what other developers use in there projects

    What are the must have libraries for any new project
    and how you organize them

    I read few articles about this but i would love to know more things from SitePoint members.

    IM NOT TALKING ABOUT FRAMEWORKS HERE.


    To what i read you organize your files this way

    img
    ---layout
    ---content
    ---and maybe more things needed

    css
    ----reset.css
    ----common.css

    js
    ----Jquery.js
    ----maybe something else

    resources
    ----library
    --------- DBclass.php
    --------- fprmvalidationclass.php
    --------- MaybeAuthClass.php
    --------- CommonFunc.php

    ----template
    ------------header.php
    ------------content.php
    ------------footer.php
    ------------sidebar.php
    ----config.php


    What do you usually do for your organization and prepare ready script for your new project....?

    Grateful as usual

  2. #2
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,271
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    Here's a simplified version of what I would use in real life. It might give you new ideas to mull.

    Code:
    src/ (your PHP here)
    	controllers/
    		BlogController.php
    	templates/
    		layout.html.php
    		Blog/
    			list.html.php
    			show.html.php
    			edit.html.php
    	model/
    		entities/
    			Blog.php
    		repositories/
    			BlogRepository.php
    	config/
    		config.yml
    vendor/ (third-party PHP here)
    	swiftmailer/
    	doctrine/
    	twig/
    web/ (publicly accessible files here)
    	images/
    	css/
    	js/
    	index.php (all requests go through this single entry point)
    "First make it work. Then make it better."

  3. #3
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jeff Mott View Post
    Code:
    src/ (your PHP here)
    	controllers/
    		BlogController.php
    	templates/
    		layout.html.php
    		Blog/
    			list.html.php
    			show.html.php
    			edit.html.php
    	model/
    		entities/
    			Blog.php
    		repositories/
    			BlogRepository.php
    	config/
    		config.yml
    vendor/ (third-party PHP here)
    	swiftmailer/
    	doctrine/
    	twig/
    web/ (publicly accessible files here)
    	images/
    	css/
    	js/
    	index.php (all requests go through this single entry point)
    Thanks Jeff for the reply

    In term of organizing its really interesting Thank you for the tip.

    But How do you route your code ....?!!!
    Do you use a particulate class or functions to handle it...

    Any other class o library you use beside the ones mentioned

    What about the rest of developers here... Any experience you would like to share with us?

  4. #4
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I checked the third party libraries you have mentioned
    I got to say Why would someone need a framework....?

    swiftmailer
    doctrine
    twig

    These libraries are nice though im not into template engines,,,..... Twig...
    I found few other libraries
    Good for any new project
    PDF Generator
    -tcpdf
    Image Manipulation
    -wideimage
    Charts
    -PHP/SWF Charts (Though i prefer a class that does not make it flash)
    Authentication
    -PHPUserClass


    Anymore suggestion for common libraries ...?

  5. #5
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,271
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by newguy99 View Post
    But How do you route your code ....?!!!
    Do you use a particulate class or functions to handle it...
    Do you mean going from a URL to a controller? The low-tech solution could look something like this:

    PHP Code:
    function routingMatch($urlPath)
    {
        if (
    $urlPath == '/') {
            return array(
    'controller' => 'Blog''action' => 'list');
        } elseif (
    $urlPath == '/show' && isset($_GET['id'])) {
            return array(
    'controller' => 'Blog''action' => 'show');
        }
    }

    // ...

    $routeParameters routingMatch($_SERVER['REQUEST_URI']); 
    Or we could use the Symfony Routing component. (Beside being a full-stack framework, Symfony is also a set of standalone libraries, so we can use the routing component without using the full framework.)

    PHP Code:
    // src/config/routing.php

    use Symfony\Component\Routing\RouteCollection;
    use 
    Symfony\Component\Routing\Route;

    $collection = new RouteCollection();

    $collection->add('blog_list', new Route('/', array(
        
    'controller' => 'Blog''action' => 'list',
    )));

    $collection->add('blog_show', new Route('/show/{id}', array(
        
    'controller' => 'Blog''action' => 'show',
    )));

    return 
    $collection
    PHP Code:
    // web/index.php

    use Symfony\Component\Routing\RequestContext;
    use 
    Symfony\Component\Routing\Matcher\UrlMatcher;

    $routes = require __DIR__.'/../src/config/routing.php';
    $context = new RequestContext('/base-url');

    $matcher = new UrlMatcher($routes$context);

    $parameters $matcher->match($_SERVER['REQUEST_URI']); 
    In my case, I do actually use the full-stack Symfony framework, so I can define my routes in a few ways. The first is the plain PHP way, similar to the config/routing.php shown above. Or I have the option to use YAML.

    Code:
    # app/config/routing.yml
    
    blog_list:
        pattern:   /
        defaults:  { _controller: AcmeBlogBundle:Blog:list }
    
    blog_show:
        pattern:   /show/{id}
        defaults:  { _controller: AcmeBlogBundle:Blog:show }
    Or I have the option to use annotations within the controller itself.

    PHP Code:
    // src/Acme/BlogBundle/Controller/BlogController.php

    use Symfony\Bundle\FrameworkBundle\Controller\Controller;
    use 
    Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

    class 
    BlogController extends Controller
    {
        
    /**
         * @Route("/")
         */
        
    public function listAction()
        {
            
    // ...
        
    }

        
    /**
         * @Route("/show/{id}")
         */
        
    public function showAction($id)
        {
            
    // ...
        
    }

    "First make it work. Then make it better."

  6. #6
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Jeff
    Its really informative.

    Now i have a good idea how it works.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •