{"id":18772470,"url":"https://github.com/eftec/example-cupcakes2","last_synced_at":"2025-12-12T20:30:15.728Z","repository":{"id":71041602,"uuid":"272819975","full_name":"EFTEC/example-cupcakes2","owner":"EFTEC","description":"Example of a project for PHP","archived":false,"fork":false,"pushed_at":"2020-08-16T21:51:06.000Z","size":1075,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-12-29T08:13:37.496Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.escuelainformatica.cl","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/EFTEC.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-06-16T21:55:38.000Z","updated_at":"2020-11-07T12:46:08.000Z","dependencies_parsed_at":"2023-06-07T07:30:29.000Z","dependency_job_id":null,"html_url":"https://github.com/EFTEC/example-cupcakes2","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EFTEC%2Fexample-cupcakes2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EFTEC%2Fexample-cupcakes2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EFTEC%2Fexample-cupcakes2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EFTEC%2Fexample-cupcakes2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EFTEC","download_url":"https://codeload.github.com/EFTEC/example-cupcakes2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239680815,"owners_count":19679505,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T19:29:11.536Z","updated_at":"2025-12-12T20:30:15.034Z","avatar_url":"https://github.com/EFTEC.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# A basic catalog of products (new Version) made with PHP\n\n![docs/result.jpg](docs/result.jpg)\n\nIt is a project that shows the creation of a basic catalog of products in an hour. This catalog has the information loaded, so we don't need to add more products.\n\n## Requirements\n\nThis project requires PHP 5.6 or higher, Mysql installed and running and PHP Composer (it is a free library)  \n\n### Composer Initialize\n\nFirst, you must initialize the project.\n\n* Create a new folder.\n* Inside the folder, run the next command:\n\n\u003e composer init \n\nAnd follow the instructions of composer.\n\nIn **composer.json** (or where we are initializing), we need to add the next libraries:\n\n\u003e ```j\n\u003e \"eftec/bladeone\": \"^3.46.1\", // to view our templates\n\u003e \"eftec/pdoone\": \"^1.48\",     // to access to the database\n\u003e \"eftec/validationone\": \"^1.24.2\", // to validate the user input.\n\u003e ```\n\n\n\n### Configuration of the database\n\nIn the file 📃**app.php**\n\n```php\n$pdoOne=new PdoOne('mysql',\"127.0.0.1\",\"root\",\"abc.123\",\"cupcakes\");\n$pdoOne-\u003elogLevel=3;\n$pdoOne-\u003eopen();\n```\n\nEdit the information of the database.  In this example: root is the user, abc.123 is the database. and cupcakes is the new schema. (we will create if there is no one)\n\nThe **loglevel** is for debug purpose. If the system fails, then it will show a lengthy message of error, showing the last query, arguments and reason of it. Later, you want to remove this line.\n\n## Initializing the database\n\nWe need to create a new schema called cupcakes, so we included a file called 📃**initialize.php**. it creates the schema, the table and it adds sample data.\n\nThis code creates all the relations.\n```php\n$relations=['cupcakes'=\u003e'CupcakeRepo']; // table=\u003eclass\n$logs=$pdoOne-\u003egenerateAllClasses($relations,'CupcakeDataBase','',__DIR__);\n```\n\n* We will use a single table called  🗒 \"cupcakes\". We will also need a class called Repository Class (or Repository Service). Usually, there is one class per table but we will have two classes per entity. \n\nIt also creates 3 files:\n\n* 📃 CupcakeDataBase.php  It is a class that is common for all the tables/entities. It is generated automatically, so you don't want to edit it manually.\n* 📃 CupcakeRepo.php  It is the first part of the Repository class. This file is not replaced if it exists. So, if you want to edit the file, then edit this one.\n* 📃 CupcakeRepoExt.php  It is the second part of the repository class.  This file is also generated automatically but you don't want to edit it.\n\n## Repository class\n\nHow this repository class works?\n\n* First, for work, you must need to inject an instance of **PdoOne** (our library to connect to the database), or we could create a public function called PdoOne() or we could create a public variable called **$pdoOne**.  All of those method works. In our case, we will use the variable called **$pdoOn**e.\n\nLet's say we want to modify a row in the table **cupcakes**.\n\n```php\n// where entity is an array with the name of the columns, case sensitve.\n// update\nCupcakeRepo::update($entity); // update a row\n// insert\nCupcakeRepo::insert($entity); // insert a row\n// delete\nCupcakeRepo::deleteById(20); // where id is the primary key that we want to delete\n// get\nCupcakeRepo::first(20); // we get a single row (or false if it fails)\n// list\nCupcakeRepo::toList(); // we get all the rows of the table\n// list filtered\nCupcakeRepo::where('Price\u003e?',[50])::toList(); //we get all the rows where price is \u003e 50 \n// List ordered and filtered\nCupcakeRepo::where('Price\u003e?',[50])::order('Name')::toList(); // select * from cupcakes where price\u003e50 order by name\n\n```\n\nExample:\n\n```php\n$entity=CupcakeRepo::factorynull(); // we create an empty array\n// $entity['IdCupcake']=5; // we don't need to edit it because the column is identity/autonumeric.\n$entity['Name']='new name'; // The case of the key of the array matter.\n$entity['Value']=555;\n$entity['Image']='image.jpg';\n$entity['Description']='It is an example';\n\nCupcakeRepo::inset($entity); // where entity is an array with the name of the columns, case sensitve.\n\n\n```\n\n## Showing the information\n\n### Listing (catalog_mysql.php)\n\nIt is simple:\n\n```php\n$cupcakes=(CupcakeRepo::order('name'))::toList(); // We read the rows from the database\n\necho $blade-\u003erun(\"cupcakes.catalog\"\n   ,['cupcakes'=\u003e$cupcakes,'postfix'=\u003e'mysql']); // cupcakes.catalog = /views/cupcakes/catalog.blade.php\n```\n\n📁 \\views   \n..... 📁 \\cupcakes   \n..... ..... 📝 catalog.blade.php   \u003c-- our view.\n\nIt will generate a file in the folder compiles\n\n📁 \\compiles\n.....  📝7e8338714c0c98ded4c4cf1724df88ebf0cfeb0d.bladec (it is generated automatically)   \n\n![](docs/listing.jpg)\n\n### Creating a new Product (create_product.php)\n\n#### If the button hasn't been clicked\n\nIf the button hasn't been clicked, then we create an empty cupcake and we show in the screen\n\n```php\n$cupcake=CupcakeRepo::factoryNull();\n```\n\n📁 \\views   \n..... 📁 \\cupcakes   \n..... ..... 📝 form.blade.php   \u003c-- our view.\n\n![](docs/create.jpg)\n\n\n\n#### If the button has been pressed.\n\nIf the button has been pressed then, initially we collect the information entered by the user and we validate it.\n\nExample:\n\n```php\n$cupcake['Name'] = $validaton\n   -\u003edef(\"\")// what if the value is not read?, we should show something (or null)\n   -\u003eifFailThenDefault(false)// if fails then we show the same value however it triggers an error\n   -\u003etype(\"varchar\")// it is required to ind\n   -\u003econdition(\"req\", \"this value (%field) is required\")\n   -\u003econdition(\"minlen\", \"The minimum lenght is 3\", 3)\n   -\u003econdition(\"maxlen\", \"The maximum lenght is 100\", 100)\n   -\u003epost('name'); // frm_name.  It also generates a message container called \"name\".\n```\n\nIf the information is correct, then we move the temporal image (if any) and we inserted into the database\n\n```php\nif (empty($validaton-\u003egetMessages())) {\n   // 1) the button was pressed and there is not error.\n   move_uploaded_file($cupcake['Image'][1],'img/'.$cupcake['Image'][0]);\n   $cupcake['Image']=$cupcake['Image'][0]; // now Image is only the name, not an array\n       CupcakeRepo::insert($cupcake);\n   header(\"Location:catalog_mysql.php\");\n}\n```\n\n\n\n### Viewing a product (detail_mysql.php)\n\nFinally, we create a new code to view a single product.\n\nInstead of getting a list of entities, we get a single line (command first)\n\n```php\n$id=$validaton-\u003etype('integer')-\u003eget('id');\n$cupcake=CupcakeRepo::first($id);\necho $blade-\u003erun(\"cupcakes.detail\",['cupcake'=\u003e$cupcake,'postfix'=\u003e'mysql']);\n```\n\n📁 \\views   \n..... 📁 \\cupcakes   \n..... ..... 📝 detail.blade.php   \u003c-- our view.\n\n![](docs/detail.jpg)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feftec%2Fexample-cupcakes2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feftec%2Fexample-cupcakes2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feftec%2Fexample-cupcakes2/lists"}