Welcome Guest, Not a member yet? Register   Sign In
VueJs + CI 4
#1

(This post was last modified: 04-26-2018, 01:58 PM by ponzo.)

I'm building a simple example to include vuejs in codeigniter.
I hoped to finish today, and share it within the CI forum

But... Im stuck now for 3 hours with posting an object to the CI 4 controller

The routes, (get is already working ) Wink

PHP Code:
$routes->post('products''Product::create');
//id or 'all'
$routes->get('products/(:any)''Product::read/$1');
$routes->put('products/(:num)''Product::update/$1');
$routes->delete('products/(:num)''Product::delete/$1'); 

The controller, to create an item , from vue with axios (POST)

PHP Code:
public function create()
{
    
    $model 
= new ProductsModel();
    $created $model->save([
        'title' => $this->request->getVar('title'),
        'description'  => $this->request->getVar('description')
    ]);
    $success = array("success");
    return $this->respond($success200);



A snippet of Vue 

PHP Code:
axios({
headers: {
'Content-Type''application/json',
},
responseType'json',
method'post',
urlurl,
data: {title:'testing title',decription:'testing desc, 

It tried 'application/x-www-form-urlencoded' as wel for the content-type

Sending the title or description from postman is working, so I tried to set the axios headers to multipart/form-data, but with no luck.

PHP Code:
POST /products/all HTTP/1.1
Host
vue-ci4.test
Content
-Typemultipart/form-databoundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
Cache
-Controlno-cache
Postman
-TokenXXXXXXX-XXXX-XXX-XXXX-XXXXXXXXX

------WebKitFormBoundary7MA4YWxkTrZu0gW
Content
-Dispositionform-dataname="title"

this is a test
------WebKitFormBoundary7MA4YWxkTrZu0gW-- 


In CI 3 i had the same problem, and fixed it with:
$_POST = json_decode(file_get_contents("php://input") , true);

I hope to wrap this thing up, with your help
Reply


Messages In This Thread
VueJs + CI 4 - by ponzo - 04-26-2018, 01:54 PM
RE: VueJs + CI 4 - by albertleao - 04-26-2018, 02:43 PM
RE: VueJs + CI 4 - by ponzo - 04-26-2018, 03:00 PM
RE: VueJs + CI 4 - by kilishan - 04-26-2018, 08:32 PM
RE: VueJs + CI 4 - by ponzo - 04-27-2018, 10:43 AM
RE: VueJs + CI 4 - by ponzo - 04-28-2018, 05:34 AM
RE: VueJs + CI 4 - by MGatner - 09-27-2019, 04:59 PM
RE: VueJs + CI 4 - by donpwinston - 09-27-2019, 08:00 PM
RE: VueJs + CI 4 - by kilishan - 09-27-2019, 09:59 PM
RE: VueJs + CI 4 - by MGatner - 09-28-2019, 04:37 AM
RE: VueJs + CI 4 - by dave friend - 09-30-2019, 01:06 PM
RE: VueJs + CI 4 - by MGatner - 09-30-2019, 05:40 PM
RE: VueJs + CI 4 - by dave friend - 10-01-2019, 08:11 AM
RE: VueJs + CI 4 - by MGatner - 10-01-2019, 07:14 PM
RE: VueJs + CI 4 - by Paradinight - 10-02-2019, 06:46 AM
RE: VueJs + CI 4 - by albertleao - 10-02-2019, 07:09 AM
RE: VueJs + CI 4 - by ignitedcms - 10-02-2019, 08:08 AM
RE: VueJs + CI 4 - by MGatner - 10-02-2019, 08:37 AM
RE: VueJs + CI 4 - by albertleao - 10-02-2019, 08:18 PM



Theme © iAndrew 2016 - Forum software by © MyBB