{"id":18772465,"url":"https://github.com/eftec/example.cupcakes","last_synced_at":"2025-12-12T20:30:15.790Z","repository":{"id":71041673,"uuid":"168953479","full_name":"EFTEC/example.cupcakes","owner":"EFTEC","description":"It is a library","archived":false,"fork":false,"pushed_at":"2019-03-09T12:24:51.000Z","size":828,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-29T08:13:36.906Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.eftec.cl","language":"HTML","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":"2019-02-03T14:23:58.000Z","updated_at":"2024-09-23T21:03:55.000Z","dependencies_parsed_at":"2023-06-07T07:45:32.241Z","dependency_job_id":null,"html_url":"https://github.com/EFTEC/example.cupcakes","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.cupcakes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EFTEC%2Fexample.cupcakes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EFTEC%2Fexample.cupcakes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EFTEC%2Fexample.cupcakes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EFTEC","download_url":"https://codeload.github.com/EFTEC/example.cupcakes/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:10.700Z","updated_at":"2025-12-12T20:30:15.260Z","avatar_url":"https://github.com/EFTEC.png","language":"HTML","readme":"# A basic catalog of products 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\nThe list of products could come from a MySql database or using the file system, you could pick one of them.\n\n## Requirements\n\nThis project requires PHP 5.6 or higher and Composer (it is a free library)  \n\n### Composer Initialize\n\nLet's open a shell in the same folder of your project and runs the next command.\n\n\u003e composer init\n\n![docs/composer_init.jpg](docs/composer_init.jpg)\n\nIt will create the file called **composer.json**. It will ask for some information.\n\n📝 composer.json\n\nYou could later edit this file.\n\n\n### Installation of Composer\n\nUsing the previous shell, let's run the command \n\n| composer install\n\n![docs/composer_install.jpg](docs/composer_install.jpg)\n\nIt will create the folder\n\n📁 \\vendor\n\nAnd the file composer.lock \n\n📝 composer.json\n\n### Installing  libraries\n\nAnd again, using the same shell, let's run the next commands.\n\n\u003e composer require eftec/bladeone  \n\u003e composer require eftec/daoone  \n\u003e composer require eftec/documentstoreone  \n\n![docs/composer_require.jpg](docs/composer_require.jpg)\n\nIt will download the next three libraries: \n\n* eftec/bladeone for the templates\n* eftec/daoone for the database (if we want to use the database)\n* eftec/documentstoreone if we're going to use the filesystem (instead of the database)\n\nThey will be stored in the folder:\n\n📁 \\vendor\n\n\n## OK, let's code (Mysql Version)\n\nWe have two versions of the same project; one uses MySql while the other relies on the file system.\n\nThis first version uses MySql, and we will use the file app.php to access the database.\n \n\u003e You must change the database's access according your system (user, password, etc.)\n\n### Application file (app.php)\n\nHere, we will set the autoload (Composer), the database and the bladeone library.\n\nThe bladeone library will be used as a template system. It uses the language \"blade\" (the same than uses Laravel)  \n\nThe class DaoOne will connect to the database.\n\n\n```php\n\u003c?php\n\nuse eftec\\bladeone\\BladeOne;\nuse eftec\\DaoOne;\n\ninclude \"vendor/autoload.php\";\n\n// we created the new connection to the database :-)\n// database located at 127.0.0.1, user root and password: abc.123, schema = cupcakes\n$db=new DaoOne(\"127.0.0.1\",\"root\",\"abc.123\",\"cupcakes\");\n$db-\u003eopen();\n\n$blade=new BladeOne(); // it will create the folders compiles/ . The folder views/ must be created\n                       // if they are not creating then you should build it manually\n```\n\n### Initializing the data createtable.php\n\nFor Mysql, we will need to create the table and add some information.\n \n\u003e **We must call this page once**. If we execute the page more than once, then it will generate an error (because the table exists).\n\nI create a file called createtable.php that creates the table and add 9 cupcakes to the table.  \n\n\n```php\n\u003c?php\n\ninclude \"app.php\";\n\n$sql=\u003c\u003c\u003cTAG\nCREATE TABLE `cupcakes` (\n  `IdCupcake` INT NOT NULL AUTO_INCREMENT,\n  `Name` VARCHAR(45) NULL,\n  `Image` VARCHAR(45) NULL,\n  `Price` DECIMAL(10,2) NULL,\n  `Description` VARCHAR(2000) NULL,\n  PRIMARY KEY (`IdCupcake`))\nTAG;\n$rows=\u003c\u003c\u003cTAG\nINSERT INTO `cupcakes`.`cupcakes` (`Name`, `Image`, `Price`, `Description`) VALUES ('Chocolate', 'cupcake1.jpg', '20', 'Chocolate');\nINSERT INTO `cupcakes`.`cupcakes` (`Name`, `Image`, `Price`, `Description`) VALUES ('Cupcake Normal', 'cupcake2.jpg', '30', 'Cupcake Normal');\nINSERT INTO `cupcakes`.`cupcakes` (`Name`, `Image`, `Price`, `Description`) VALUES ('Gourmet', 'cupcake3.jpg', '35.5', 'Gourmet');\nINSERT INTO `cupcakes`.`cupcakes` (`Name`, `Image`, `Price`, `Description`) VALUES ('Apple Pie', 'cupcake4.jpg', '43.3', 'Apple Pie');\nINSERT INTO `cupcakes`.`cupcakes` (`Name`, `Image`, `Price`, `Description`) VALUES ('Sprinkles', 'cupcake5.jpg', '24.3', 'Sprinkles');\nINSERT INTO `cupcakes`.`cupcakes` (`Name`, `Image`, `Price`, `Description`) VALUES ('Butter', 'cupcake6.jpg', '32.2', 'Butter');\nINSERT INTO `cupcakes`.`cupcakes` (`Name`, `Image`, `Price`, `Description`) VALUES ('Lemon', 'cupcake7.jpg', '22.3', 'Lemon');\nINSERT INTO `cupcakes`.`cupcakes` (`Name`, `Image`, `Price`, `Description`) VALUES ('Brownies', 'cupcake8.jpg', '32.2', 'Brownies');\nINSERT INTO `cupcakes`.`cupcakes` (`Name`, `Image`, `Price`, `Description`) VALUES ('Bubbly', 'cupcake9.jpg', '33.2', 'Bubbly');\nTAG;\n\n$db-\u003erunRawQuery($sql);\n\n$db-\u003erunMultipleRawQuery($rows);\n```\n\n\u003e Fatal error: Uncaught Exception: Exception raw CREATE TABLE `cupcakes` ( ... \n\nLet's say that it fails. It could fail because:\n\n* The table already exists.\n* We don't have access to the database (you should edit the file app.php)\n* We don't have the permissions to create a table.\n\n\n### Controller (catalog_mysql.php).\n\nNow, let's show the catalog.  We will do the next operations:\n\n* Read the list of cupcakes from the database.\n* Sends the list to the template\n\n```php\n\u003c?php\ninclude \"app.php\";\n\n$cupcakes=$db-\u003eselect(\"*\")-\u003efrom(\"cupcakes\")-\u003eorder(\"name\")-\u003etoList();\n\necho $blade-\u003erun(\"cupcakes.catalog\"\n    ,['cupcakes'=\u003e$cupcakes,'postfix'=\u003e'mysql']);\n```\n\nWe are also passing the variable postfix. It is used to create the link to the right version.\n\n### View (views/cupcakes/catalog.blade.php)\n\nOk, it is a bit long, I started with the startup page of Bootstrap, I added some cards and  the annotation  @foreach cycle\n\nThe images exist in the folder:\n\n📁  \\img   \n\nThis template must exist in the folder:\n\n📁 \\views   \n..... 📁 \\cupcakes   \n..... ..... 📝 catalog.blade.php   \n\nWhy?, the views folder is the default folder of the view (BladeOne)\n\nThe second folder and the file comes from the line:\n\n\u003e echo $blade-\u003erun(\"cupcakes.catalog\",...\n\nwhere **cupcakes** is a folder, and **catalog** is the file (plus extension .blade.php)\n\n\n```html\n\u003c!doctype html\u003e\n\u003chtml lang=\"en\"\u003e\n\u003chead\u003e\n    \u003c!-- Required meta tags --\u003e\n    \u003cmeta charset=\"utf-8\"\u003e\n    \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1, shrink-to-fit=no\"\u003e\n    \u003c!-- Bootstrap CSS --\u003e\n    \u003clink rel=\"stylesheet\" href=\"http://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css\" integrity=\"sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS\" crossorigin=\"anonymous\"\u003e\n    \u003ctitle\u003eHello, world!\u003c/title\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n\u003cdiv class=\"container\"\u003e\n    \u003ch1\u003eCupcakes World\n        \u003csmall class=\"text-muted\"\u003ePick your cupcake\u003c/small\u003e\n    \u003c/h1\u003e\n    \u003cdiv class=\"row\"\u003e\n        @foreach($cupcakes as $cupcake)\n        \u003cdiv class=\"col-md-4\"\u003e\n            \u003cdiv class=\"card\"\u003e\n                \u003ca href=\"detail_{{$postfix}}.php?id={{$cupcake['IdCupcake']}}\"\u003e\n                    \u003cimg src=\"img/{{$cupcake['Image']}}\" class=\"card-img-top\" alt=\"{{$cupcake['Image']}}\"\u003e\n                \u003c/a\u003e\n                \u003cdiv class=\"card-body\"\u003e\n                    \u003cdiv class=\"row\"\u003e\n                        \u003cdiv class=\"col-md-7\"\u003e\n                            \u003ch5 class=\"card-title\"\u003e{{$cupcake['Name']}}\u003c/h5\u003e\n                        \u003c/div\u003e\n                        \u003cdiv class=\"col-md-5 text-right\"\u003e\n                            \u003cp class=\"card-text\"\u003ePrice ${{$cupcake['Price']}}\u003c/p\u003e\n                        \u003c/div\u003e\n                    \u003c/div\u003e\n                    \u003ca href=\"detail_{{$postfix}}.php?id={{$cupcake['IdCupcake']}}\" class=\"btn btn-primary\"\u003eEat Me\u003c/a\u003e\n                \u003c/div\u003e\n            \u003c/div\u003e\n            \u003cbr\u003e\n        \u003c/div\u003e\n        \n        @endforeach()\n          \n    \u003c/div\u003e\n\u003c/div\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\nThe magic is done using the annotation of Blade **@some-operator**\n\n\u003e @foreach($cupcakes as $cupcake)\n\nIt generates a loop of the variable $cupcakes. Where $cupcakes comes from?. From here:\n\n\u003e echo $blade-\u003erun(\"cupcakes.catalog\",[**'cupcakes'**=\u003e$cupcakes,...]);\n\nNext, we should show each value using the annotation of Blade **{{}}**\n\n\u003e \u003cimg src=\"img/{{$cupcake['Image']}}\" ...\u003e\n\n## Let's code (Document Version)\n\nIt doesn't use Mysql, and it stores the information into the file system (folders and files)\n\n### Application file\n\nHere, we will set the autoload (Composer), the document and the bladeone library.\n\nThe bladeone library will be used as a template system. It uses the language \"blade\" (the same than uses Laravel)  \n\nThe class DocumentStoreOne will connect to the filesystem-based database. We set the library, the serialization (we will use json) and the extension.\n\n\n```php\n\u003c?php\n\nuse eftec\\bladeone\\BladeOne;\nuse eftec\\DocumentStoreOne\\DocumentStoreOne;\n\ninclude \"vendor/autoload.php\";\n\n// folder /db/cupcake\n$doc=new DocumentStoreOne(\"db\",\"cupcake\",null, DocumentStoreOne::DSO_FOLDER,false);\n$doc-\u003eautoSerialize(true,\"json_array\"); // autoserialize the object using json\n$doc-\u003edocExt=\".json\";\n\n\n$blade=new BladeOne(); // it will create the folders compiles/ . The folder views/ must be created\n                       // if they are not created, then you should build it manually\n```\n\n### Initializing the data \n\nWe will use the folder as our database.\n\n📁 \\db   \n..... 📁 \\cupcake   \n..... ..... 📝 *.json\n\n### Controller (catalog_document.php)\n\nNow, let's show the catalog.  We will do the next operations:\n\n* Read the list of cupcakes from the document repository.\n* Sends the list to the template\n\n```php   \ninclude \"app_doc.php\";\n$cupcakes=$doc-\u003eget(\"cupcakes\");\necho $blade-\u003erun(\"cupcakes.catalog\",['cupcakes'=\u003e$cupcakes,'postfix'=\u003e'document']);\n```\n\nAnd we will use the same views used in the previous exercise.\n\nThe line \n\n\u003e $cupcakes=$doc-\u003eget(\"cupcakes\");\n\nIt reads from the document base /db/cupcake/ the file cupcakes.json and returns a list of cupcakes.  \nThis operation could be quite fast since it is only reading from the file system. \nHowever, it doesn't allow analysis (such as sort, filter, and grouping). If we want something like this, then we must do it manually. \n\n\n   \n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feftec%2Fexample.cupcakes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feftec%2Fexample.cupcakes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feftec%2Fexample.cupcakes/lists"}